Hello,
I have to validate that there is information and radio buttons have been selected. Also, I need to be able to reset the text boxes. When I click the submit button, it does not do the validation and when I click the reset button, it does nothing. Here's what I have, but it doesn't seem to work? Please help me with this.
Thanks,
Tom
I have to validate that there is information and radio buttons have been selected. Also, I need to be able to reset the text boxes. When I click the submit button, it does not do the validation and when I click the reset button, it does nothing. Here's what I have, but it doesn't seem to work? Please help me with this.
Thanks,
Tom
Code:
<?php echo '<?xml version="1.0" encoding="IUTF-8"?>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<title>Scion tC Catalog</title>
</head>
<body>
<script type="text/javascript">
function validateForm()
{
var age=document.forms["myForm"]["fage"].value;
var x=document.forms["myForm"]["fname"].value;
var scion = getCheckedValue(document.forms["myForm"].elements["scion"]);
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
if (isNaN(age)||age < 1||age > 100)
{
alert("Age must be between 1-100");
return false;
}
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
if (cSelect.length == 0) {
alert("Please give a rating");
}
else {alert(cSelect);
}
function formReset()
{
document.getElementById("frm1").reset();
}
</script>
<a name="Top" id="Top"></a>
<h1 class="">2010-14 Scion tC Catalog</h1>
<table class="centered-table">
<tr>
<th><a href="index.php">Home</a></th>
<th><a href="list.php">List</a></th>
<th><a href="table.php">Table</a></th>
</tr>
</table>
<br />
<h2>2010-14 Scion tC Release Series and Base Models</h2>
<p class="sansserif">The best of the Scion tC models<br />
<br /></p>
<form id="frm1" name="myForm" action="thankyou.php" onsubmit="return validateForm()" method="post">First name: <input type="text" name="fname" /> Age: <input type="text" name="fage" /> <input type="submit" value="Submit" /> <input type="button" onclick="formReset()" value="Reset form" /></form>
<br />
<table class="table1">
<tr>
<th>Select</th>
<th>Series</th>
<th>Photo</th>
<th>Description</th>
<th>Price</th>
</tr>
<tr>
<td><input type="radio" name="scion" id="r1" value="1" /><br /></td>
<td>2010 Scion tC RS 6.0</td>
<td><img src="pictures/2011S.jpg" alt="2010 Scion tC RS 6.0" /></td>
<td>Speedway Blue: 1,100 units produced. If blue is your color, then this is the car for you!</td>
<td>$22,999</td>
</tr>
<tr>
<td><input type="radio" name="sicon" id="r2" value="2" /><br /></td>
<td>2012 Scion tC RS 7.0</td>
<td><img src="pictures/2012S.jpg" alt="2012 Scion tC RS 7.0" /></td>
<td>High Voltage Yellow: 2,200 units produced. If yellow is your color, then this is the car for you!</td>
<td>$23,999</td>
</tr>
<tr>
<td><input type="radio" name="sicon" id="r3" value="3" /><br /></td>
<td>2013 Scion tC RS 8.0</td>
<td><img src="pictures/2013S.jpg" alt="2013 Scion tC RS 8.0" /></td>
<td>Absolutely Red: 2,000 units produced. If red is your color, then this is the car for you!</td>
<td>$24,999</td>
</tr>
<tr>
<td><input type="radio" name="sicon" id="r4" value="4" /><br /></td>
<td>2014 Scion tC Base Model</td>
<td><img src="pictures/2014S.jpg" alt="2014 Scion tC Base Model" /></td>
<td>If you love a nice sports car and easy on gas, then this is the car for you!</td>
<td>$18,999</td>
</tr>
</table>
</body>
</html>
Comment