Guest jrheeder Posted May 4, 2006 Share Posted May 4, 2006 HiI have to create a HTML/Javascript program which does the following things1. Uses one window prompts to allow the user to enter their Code_Id (which is between 1 and 15) into a variable called Code_Id.2. Uses a function which will accept the string values from a caller function, converts it to an integer (using parseInt), test to see if the Code_Id lies between 1 and 15 and outputs a alert box with an appropriate message to tell the user if the Code_Id is valid or not. . 3. Displays a message from the body of the program which thanks the user for entering their Code_Id. Now I ahve created the code below but the only this that seems to work it the promts box that asks for the Id can anyone please help!!!! Da Code <html><head><title>Code ID Exercise</title><script language='JavaScript'>function ask(String_Id){ var valid = false; var id = 0 id = parseInt(String_Id); document.write("hello"); if (id >= 1) && (id <= 15) { valid = true; } else { window.alert("The ID entered is invalid please enter again"); }}</script></head><body><script language='JavaScript'> var Code_Id = window.prompt("Please enter your ID please",""); document.write(Code_Id); ask(Code_Id);</script><h2>Thank you for entering your ID</h2></body></html> Link to comment Share on other sites More sharing options...
scott100 Posted May 4, 2006 Share Posted May 4, 2006 <html><head><title>Code ID Exercise</title><script language='JavaScript'>function ask(String_Id){ id = parseInt(String_Id); if ((id <1) || (id >15)) { alert(String_Id+" is incorrect"); }}</script></head><body><script language='JavaScript'>var Code_Id = window.prompt("Please enter your ID please","");ask(Code_Id);document.write(Code_Id);</script><h2>Thank you for entering your ID</h2></body></html> Link to comment Share on other sites More sharing options...
aspnetguy Posted May 4, 2006 Share Posted May 4, 2006 try this <html><head><script type="text/javascript"> onload= function getCode() { var Code_Id = prompt('Please enter your code',''); var msg, html; var objOutput = document.getElementById('divOutput'); objOutput.innerHTML = ''; if(isValid(Code_Id)) { msg = 'Your code appears to be valid!'; html = 'Thank you for entering your code'; } else { msg = 'Your code is invalid!'; html = 'Your code was invalid. ' + 'Click <a href="javascript:getCode()">here</a> to re-enter your code.'; } alert(msg); objOutput.innerHTML = html; } function isValid(ID) { var parseId = parseInt(ID); if(parseId >= 1 && parseId <= 15) return true; else return false; }</script></head><body><div id="divOutput"></div></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now