Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Javascript loop question?

I'm trying to make a small function, the user enters a 'Phrase' in the textbox, when the button is clicked I want the document to write it 10 times.. here's my code; I know I'm close but what am I doing wrong?

<script language="javascript">

function phrasecount() {

var i=1

var phval = document.phraseform.ph.value;

for (i=1;i<=10;i++)

{

document.write (phval);

document.write("<br />");

}

</script>

<form name="phraseform" id="phraseform">

Enter a phrase: <input type="text" name="ph" id="ph" size="100" value="" /><br>

<input type="button" value="Display" onClick='return phrasecount()' />

</form>

Update:

Excellent answer Ben, 5 *s from me. :)

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    <script language="javascript">

    function phrasecount() {

    var i=1;

    var phval = document.phraseform.ph.value;

    for (i=1;i<=10;i++){

    document.write (phval);

    }

    }

    </script>

    <form name="phraseform" id="phraseform">

    Enter a phrase: <input type="text" name="ph" id="ph" size="100" value="" /><br>

    <input type="button" value="Display" onClick='phrasecount();' />

    </form>

    Hey bud when you broke the line you created a javascript error look at how i did it.

    http://everythingfla.com/ - my online flash and actionscript online school JavaScript and flash are so closly tied together that the first 20 hours of video more or less overlap the languages.

  • Anonymous
    1 decade ago

    If you want to write on separate lines, try

    document.write (phval+"< ;br />"); (without the space between t and ;)

Still have questions? Get your answers by asking now.