0

hi am having a small javascript trouble here pliz help out

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<!-- help out pliz -->
<!-- i need javasript that wil return true when the code 12345 is entered in the input field and place an image accept.gif in the div id =jim3 or false if any other chaaracter is input and show an image denied.gif in div id=jim3 with an error allert box -->
<!--  -->
<title>javascript demo</title>

</head>
<body>
<div id=jim2 >
<form name=test id=jim action="">
	enter code <br>
    <input type="text" id=jim1> <br> 
    <input name="jim4" type="button" value="press to continue">
    </form>
    
    <div id=jim3>
    </div>
 </form>
 </div>   
</body>
</html>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by ko ko
0

Could you at least make an attempt to write the code? Then when you get stuck ask a question that pertains to what you are stuck on.

0
function verify(){
   var image = new Image();
   if(!document.getElementById('jim1').value().match('/[0-9]/')){
       image.src = 'path/success-image.gif';
       document.getElementById('jim3').appendChild(image);
   }
   else{
       image.src = 'path/error-image.gif';
       document.getElementById('jim3').appendChild(image);
       alert('Error !');
   }
   return false; // this line will prevent the form submitted
}

Attach the above function to your button with onclick event. Note that it was not tested and may not work. Try yourself !

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.