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