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>
Member Avatar for stbuchok

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.

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 !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.