1 Replies - 864 Views - Last Post: 04 February 2009 - 12:49 AM

#1 yreene   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-February 09

html

Post icon  Posted 04 February 2009 - 12:27 AM

the validation of my html is not working properly
<html>
<head>
<script type="text/javascript">
	function Validatingtext(regform)
	{
	if(regform.name.value=="")
	{
	return false;
	}
	if(regform.address.value=="")
	{
	return false;
	}
	if(regform.age.value=="")
	{
	return false;
	}
	if(regform.zip code.value=="")
	{
	return false;
	}
	return true;
	}

	function Validatingradio(regform)
	{
	if(regform.BMW[0].checked==true)
	{
	return true;
	}
	if(regform.BMW[1].checked==true)
	{
	return true;
	}
	if(regform.BMW[2].checked==true)
	{
	return true;
	}
	if(regform.BMW[3].checked==true)
	{
	return true;
	}
	if(regform.Porsche[4].checked==true)
	{
	return true;
	}
	if(regform.Porsche[5].checked==true)
	{
	return true;
	}
	if(regform.Porsche[6].checked==true)
	{
	return true;
	}
	return false;
	}
	
	
	function Validatingcheck(regform)
	{
	if(regform.option1[0].checked==true)
	{
	return true;
	}
	if(regform.option1[1].checked==true)
	{
	return true;
	}
	return false;
	}

	function doSubmit(regform)
	{
	if(Validatingtext(regform)==false)
	{
	alert("erorr");
	return;
	}
	if(Validatingradio(regform)==false)
	{
	alert("erorr");
	return;
	}
	if(Validatingcheck(regform)==false)
	{
	alert("erorr");
	return;
	}
	function doClear(regform);
	{
	regform.name.value="";
	regfrom.address.value="";
	regfrom.age.value="";
	regfrom.Zip code.value="";
	regform.BMW[0].checked=false;
	regform.BMW[1].checked=false;
	regform.BMW[2].checked=false;
	regform.BMW[3].checked=false;
	regform.PORSCHE[4].checked=false;
	regform.PORSCHE[5].checked=false;
	regform.PORSCHE[6].checked=false;
	regform.option1.[0].checked=false;
	regform.option1.[1].checked=false;
	return;
	}

</script>
<body background="17.jpg"> 
<form name="regform">
		
	<table border="1" cellpadding="5" cellspacing="5" width="45%">
	<tr>
	<h1><i><center><font color="red"> Choose Your Ride</i></h1>
	<th>Name:<BR><input type="text" size="25"><BR></th> 
	<th>Address:<BR><input type="text" size="25"><BR></th>
	<th>Age:<BR><input type="text" size="25"><br></th>
	<th>Zip Code:<BR><input type="text" size="25"></th>
	</tr>

	<table border="1" cellpadding="5" cellspacing="5" width="45%">
	<center><h2>TYPE of CAR</h2>
	<i><h3>BMW</h3></i>
	<input type="radio" name="BMW" value="car">2009 BMW 128<br>
	<input type="radio" name="BMW" value="car">2009 BMW 328 <br>
	<input type="radio" name="BMW" value="car">2009 BMW 335 <br>
			<input type="radio" name="BMW" value="car">2009 BMW 335d <br>
	
	<i><h3>PORSCHE</h3></i>
	<input type="radio" name="PORSCHE" value="car">Porsche 911<br>
	<input type="radio" name="PORSCHE" value="car">Porsche Cayman<br>
	<input type="radio" name="PORSCHE" value="car">Porsche Caynenne<br>
	
	<H4>DO YOU WANT TO BUY?</H4>

	<input type="checkbox" name="option1" value="CAR">YES<br>
	<input type="checkbox" name="option1" value="CAR">NO<br>

	<input type="submit" value="SUBMIT" onsubmit="doSubmit(regform)">
	<input type="submit" value="CLEAR"  onsubmit="doClear(regform)">
	</center>	
</form>
</body>
</head>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: html

#2 5thWall   User is offline

  • Occasional Member

Reputation: 31
  • View blog
  • Posts: 530
  • Joined: 17-September 08

Re: html

Posted 04 February 2009 - 12:49 AM

Well, first of all. You haven't named all of your inputs. They all need the name attribute before you can check them with Javascript.

<th>Name:<BR><input type="text" name="name" size="25"><BR></th>
th>Address:<BR><input type="text" name="address" size="25"><BR></th>

Just like that for all of the inputs. You'll also need to make sure your Javascript function is called when the user tries to submit the page. You can handle that in the form tag.

<form id="regform" onsubmit="return doSubmit(this)>


Also, you'll probably want to change your clear button to a real button not a submit button:

<input type="button" value="CLEAR" onclick="doClear(regform)"

That should get you started.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1