Jump to content

inputbox equals veraible - if else document.write


rx3mer

Recommended Posts

Hey

 

I have simple question. I want to check if a value from input box is equals to veriable and if it is to display something like a text.

 

So if i have veriable called "hello" and if i type hello in the inputbox ill display "this works!" else "error".

 

here is something that i tryed to do but is not working for some reason :-/

 

 

<script language="javascript" type="text/javascript">




function showAlert() {
string1=document.getElementById("x").value;

if (string1 = x)
{
document.write("hello world");
}
else{
document.write("error");
}

}
</script>
<p><input name="string1" type="text" id="x" value="string1"></p>
<p><input type="button" value="Click here" onClick="showAlert();"></p>



 

Тhanks!

need to wake up  :shy:

 

Problem solved! Thanks thorpe!

 

<script language="javascript" type="text/javascript">




function showAlert() {
var string1 = "hello";

if (string1 == x.value)
{
document.write("hello world");
}
else{
document.write("error");
}

}
</script>
<p><input name="x" type="text" id="x" ></p>
<p><input type="button" value="Click here" onClick="showAlert();"></p>


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.