rx3mer Posted December 19, 2010 Share Posted December 19, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/222167-inputbox-equals-veraible-if-else-documentwrite/ Share on other sites More sharing options...
trq Posted December 19, 2010 Share Posted December 19, 2010 Firstly the comparison operator is == not = secondly, x is not defined anywhere within your function. Quote Link to comment https://forums.phpfreaks.com/topic/222167-inputbox-equals-veraible-if-else-documentwrite/#findComment-1149374 Share on other sites More sharing options...
rx3mer Posted December 20, 2010 Author Share Posted December 20, 2010 need to wake up 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> Quote Link to comment https://forums.phpfreaks.com/topic/222167-inputbox-equals-veraible-if-else-documentwrite/#findComment-1149375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.