Jump to content

text box


Guest display

Recommended Posts

I have this html code:

<html><body><script type="text/javascript">var name=prompt("Please enter your name","")var age=prompt("Please enter your age","")try{if(age<18)throw "Err1"else if(isNaN(age))throw"Err2"elsethrow"right"}catch(re){if(re=="Err1")document.write("sorry "+name+" you are too young to enter")if(re=="Err2")alert("You must enter a number")if(re=="right")document.write("Hello "+name+" you are "+age+" years old!")}</script>

I want to do the same thing but instead of prompt boxes I want it to be two text boxes and a submit button. is this possible? if so...how?

Link to comment
Share on other sites

Try this?

<html><head><script type="text/javascript">function goSub() {var name=document.getElementById("namebox").value;var age=document.getElementById("agebox").value;document.getElementById("namebox").style.visibility="hidden"document.getElementById("agebox").style.visibility="hidden"document.getElementById("gobut").style.visibility="hidden"try{if(age<18)throw "Err1"else if(isNaN(age))throw"Err2"elsethrow"right"}catch(re){if(re=="Err1")document.write("sorry "+name+" you are too young to enter")if(re=="Err2")alert("You must enter a number")if(re=="right")document.write("Hello "+name+" you are "+age+" years old!")}}</script></head><body><input id="agebox" type="text" value="Age?"><input id="namebox" type="text" value="Name?"><input type="button" value="Go" onclick="goSub()" id="gobut" /></body></html>

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...