0

Okay, I'm ashamed to be asking, but it just isn't clicking. My brother-in-law has an assignment to have a text box and then a command button. When the button is pressed, it will loop 10 times printing whatever was in the text box. Should be simple - I know!

I know the error is on this line:

<input type="button" value="Press Here" onClick="sayit(document.getElementById('myTextField').value) ">

Here's what we have:

<html>
<head>
<title> Homework #11 part 2 </title>
<script type="text/javascript">
function sayIt(var message){

        count = 1;
        num = 10;
        while (count <= num) {
        document.write(message);    
            document.write("<br/>");

            count = count + 1;
        }


}
</script>
</head>
<body>
<p>
Type in a phrase.
<input type='text' id='myText' />


<br />
<input type="button" value="Press Here" onClick="sayit(document.getElementById('myTextField').value) ">

</p>
</body>
3
  • <html> <head> <title> Homework #11 part 2 </title> <script type="text/javascript"> function sayIt(var message){ count = 1; num = 10; while (count <= num) { document.write(message); document.write("<br/>"); count = count + 1; } } </script> </head> <body> <p> Type in a phrase. <input type='text' id='myText' /> <br /> <input type="button" value="Press Here" onClick="sayit(document.getElementById('myTextField').value) "> </p> </body> </html> Commented Apr 27, 2011 at 1:10
  • Where is the "myTextField" element in the page? Commented Apr 27, 2011 at 1:15
  • use a for loop for that if its for school... for (i=0; i < 10; i++){document.write(message)} Commented Apr 27, 2011 at 2:30

2 Answers 2

5

The code has three thins wrong.

1) function sayIt(var message) should be function sayIt(message) 2)onClick="sayit(....)" should be onClick="sayIt(....)"

sayIt is function name

3)document.getElementById('myTextField').value should be document.getElementById('myText')

myText is input element's id attribute

Sign up to request clarification or add additional context in comments.

Comments

4

You've got three things wrong.

http://jsfiddle.net/userdude/jcfD8/

Hints - you don't need var in your function declaration, your id is not right, and you "misspelled" sayIt

( ^ If you care to see the answers, they are above ^ )

Invest in Firebug. It gave me all the answers I needed. ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.