Start New Discussion within our Web Development Community

I was given this assignment:
Create an html form. Include at least two text boxes, at least one of which must be numeric, a set of at least three radio buttons, a submit button and a reset button. Upload to your account. Make sure the permissions are correct. Name it hw1.html. Create a php script called hw1.php using an ASCII text editor that takes the data and creates a simple response html page verifying the data entered. For full credit, an if statement using the value of the numeric field must be included to give different output (such as messages, colors, etc.) and error checking must be included. Submit the entire url in the dropbox.

I didn't know how to go about the "numeric only" thing so I decided I would use javascript to check the value before submittal. Unfortunately, it doesn't run at all and the form gets submitted regardless. Since its past due I feel comfortable asking for help. I want to know how I could have done this better and how I could've done it in javascript.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "$
<html xmlns="">
<title>Homework 1</title>
<script type="text/javascript">
function onlyNumbers()
var b = document.getElementById('id').value;
alert("Numeric value for student id needed");
function checkForm()
var b = document.getElementById('id').value;
var d = b * 2;
if(d == b)
alert("Numeric value for student id needed");
if(navigator.appName == "Microsoft Internet Explorer")
<form id="form" name="form" method="post" action="h1.php" onsubmit="checkform();">
<p>Name:<input type="text" name="name" id="name" /></p>
<p>Enter ID:<input type="text" name="id" id="id" /></p>
<p>You Are:

full time: <input type="radio" name="student" id="student" value="full" />

part time: <input type="radio" name="student" id="student" value="part" />
<p>Financial aid?<input type="checkbox" name="aid" value="yes" id="aid" /></p>
<input type="submit" name="submit" value="submit" />
<input type="button" name="reset" value="reset" onClick="window.navigate("cs4.sunyocc.ed…

It's quite simple.

Arrange for checkForm() to return false if any of the validations fails or true if they all pass.

Also, modify the HTML such that the returned value is itself returned by the onsubmit handler:

<form ... onsubmit="return checkform();">


<input type="submit">

always submits the form regardless of any javascript validation
you should try

<input type="button" on click="checkValidation()">

and then submit your form using javascript



This article has been dead for over six months. Start a new discussion instead.