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!

Link to comment
Share on other sites

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>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.