Jump to content

[SOLVED] Image Display


Dethman

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/151320-solved-image-display/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/151320-solved-image-display/#findComment-795449
Share on other sites

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.