0

I want to combine these two blocks in the script. I want it so that when you type river into the text box i can give a good job statement or post a link. I don't know what to use as the variable in the second statement. Which is the if statement.

var userInput.value=river;
if(userInput.value)=="river"){
document.write("hey");
}
<br/>
function changeText2(){
var userInput=document.getElementById('userInput').value;
document.getElementById('boldStuff2').innerHTML=userInput;
}


</script>
<p>What has a mouth but can't chew?<b id='boldStuff2'>???</b></p>
<input type='text' id='userInput' value='Enter Answer Here'/>
<input type='button' onclick='changeText2()' value='Answer'/>



</head>
</html>
1
  • var userInput.value=river; This makes my head spin Commented Mar 14, 2013 at 6:49

2 Answers 2

1

First three lines of that code are not only wrong logically, they are unnecessary as well. Try a simple version

<script>
function changeText2(){
var userInput=document.getElementById('userInput').value;

if(userInput.toLowerCase()=="river")
{
alert("Good Job");
}

document.getElementById('boldStuff2').innerHTML=userInput;
}


</script>
<p>What has a mouth but can't chew?<b id='boldStuff2'>???</b></p>
<input type='text' id='userInput' value='Enter Answer Here'/>
<input type='button' onclick='changeText2()' value='Answer'/>



</head>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks i am really new and appreciate this
0

se this function in your JScript code

   function changeText2(){
     var userInput=document.getElementById('userInput').value;
     if(userInput=="river")
     {
      document.write("");
     }
     document.getElementById('boldStuff2').innerHTML=userInput;
   }

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.