Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 03-24-2006, 11:31 PM   #1
Solid State Member
Join Date: Jan 2006
Posts: 8
Smile Help needed with JS functions in xhtml

(this is for college) Basically, i've reated a form, now I have to add Javascript to the form. Its a basic survey form, the first question in the form is displayed through radio buttons. I have to add Javascript to this bit, the user must answer this question, if they don't (ie miss it) and answer the question below, then they must be alerted, can anyone help with how to do this?


Trez is offline   Reply With Quote
Old 03-25-2006, 08:03 AM   #2
Site Team
root's Avatar
Join Date: Mar 2004
Posts: 8,082
Default Re: Help needed with JS functions in xhtml

just off the top of my head...

all you need to do is pass the name of the previous element to a function so that it can check that is have data...

<head><script type="text/javascript">
function check_box(element)
if (element == "name") { if (document.form1.name.value == "") { alert("you must fill in your name")} } 
if (element == "address") { if (document.form1.address.value == "") { alert("you must fill in your address")} }
<form name="form1">
name:<input type="text" name="name"  />
address:<input type="text" name="address" onclick="check_box('name')" />
postcode: name:<input type="text" name="postcode" onclick="check_box('address')" />
<input type="submit">
there are a lot more ways to do this that are better,
for instance checking the form as a whole when it is submitted, that way the user can skip questions and come back later.
I didnít fight my way to the top of the food chain to be a vegetarianÖ
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 06:06 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0