Dethman Posted March 27, 2009 Share Posted March 27, 2009 Its my first day exploring into JS and Im trying to get the information from an input field every time something is typed and if the information typed in is the same as a PHP session wright some html with an image src heres my code so far can you see if im doing it right, Thanx, Brian Flores, CEo NimbusGames,llc <script type="text/javascript"> function isCorrect( code,actuall ){ if (code != actual){ document.getElementById("display7").innerHTML="<img src='images/x.gif'>"; } else{ document.getElementById("display7").innerHTML="<img src='images/checked.gif'"; } } </script> <html> <head> <title> Onclick - Random </title> </head> <body> <input type='text' name="random_letters" onChange="javascript: isCorrect()" <div id="display7"></div> </body> </html> The part that Im stuck on is how do I get the information from the input field to the function call I know in PHP $_POST['s'] would have been used for this but im not sure what I would use for this type of thing Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 27, 2009 Share Posted March 27, 2009 i might be wrong, but you can also pass php in Javscript.. I did something like this recently document.getElementById("slideshow").setAttribute("src", "<?php echo $chapter;?>/"+galleryarray[curimg]) Quote Link to comment Share on other sites More sharing options...
shutat Posted March 27, 2009 Share Posted March 27, 2009 If the image needs to change as the user types, then I *think* something like below may work. onChange is triggered when the textbox loses focus and its value was changed. "this" contains properties of the target. For example, you could add another parameter to your function that includes the "name" parameter of the input box by adding onkeypress="isCorrect(this.name, this.value, 'actual_text');" <input type='text' name="random_letters" onkeypress="isCorrect(this.value, 'some_actual_value');"> HTH Quote Link to comment 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.