![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Moderator/Gearhead
|
Javascript problemo
On the form that I made, I'm using Javascript to bring up a warning when someone doesn't fill out a required field. However, it's giving me pain. First problem, only the first 3 required fields make a warning popup when the submit button is pressed. There are seven required fields. Also, the submit button doesn't work. I mean, when pressed it will do the popup warning for 3 required fields, but when those fields are filled out, when you press it doesn't do a thing. I'm not sure if I did the javascript right, I was using from a sample and just duplicated each line as I needed it. The form's name is PartsRequest. Here's the JS that I have in <head>:
<head> <script language="JavaScript" type="text/javascript"> function submitForm() { if(document.PartsRequest.Name.value.length < 1) { alert("Please enter your name."); document.PartsRequest.Name.focus(); return; } else if(document.PartsRequest.email.value.length < 4) { alert("Please enter a valid e-mail address."); document.PartsRequest.email.focus(); return; } else if(document.PartsRequest.Equip_brand.value.length < 1) { alert("Please enter a equipment brand."); document.PartsRequest.Equip_brand.focus(); return; } else if(document.PartsRequest.Equipment_type.value.length < 1) { alert("Please enter a equipment type."); document.PartsRequest.Equipmenttype.focus(); return; } else if(document.PartsRequest.Equip_model.value.length < 1) { alert("Please enter a equipment model."); document.PartsRequest.Equip_model.focus(); return; } else if(document.PartsRequest.Equip_serial.value.length < 1) { alert("Please enter a equipment serial number."); document.PartsRequest.Equip_serial.focus(); return; } else if(document.PartsRequest.Parts.value.length < 1) { alert("Please enter parts description."); document.PartsRequest.Parts.focus(); return; } document.PartsRequest.submit(); } </script> </head> Those are all the required fields in my form. And here;s the submit button code: <input type="Button" name="submitBtn" value="Submit Request" onClick="submitForm();"> I can post the form too, if needed, but it's kinda long. I hope someone can help me ![]() EDIT: Oh, here's the link to the page, you can see for yourself how nothing happens when you click submit: http://www.edgeandengine.com/general/parts-lookup.html
__________________
![]() Registered Linux User #435503 Don't let socialists take over this country. Vote Nobama 2008! Last edited by K-B : 01-27-2007 at 06:54 PM. |
|
|
|
|
|
#2 (permalink) | |
|
Moderator/Gearhead
|
Ok, I figured out part of the problem.
Quote:
__________________
![]() Registered Linux User #435503 Don't let socialists take over this country. Vote Nobama 2008! |
|
|
|
|
|
|
#3 (permalink) |
|
Design Team Member
Join Date: Nov 2004
Posts: 548
OS: Windows 98SE & Windows 2K & Windows XP Pro SP3 browsing the web with FF, Opera, Safari and IE.
|
@ kbalona: See this page all the way at the bottom, this seems to be the code:
document.forms[0].radios[i].checked = true; form http://www.quirksmode.org/js/forms.html |
|
|
|
|
|
#4 (permalink) |
|
Registered User
Join Date: Jan 2007
Posts: 128
OS: xp
|
Generally with radio buttons you don't write (testing) code to make sure a radio button has been selected at run time. You select one to be the default at design time. The user can change it but at least you always have a least one selected. Like this:
Male: <input type="radio" name="Sex" value="male" checked="checked"> Female: <input type="radio" name="Sex" value="female"> By the way ALL your elses are redundant. Either return is called in an if statement or it isn't in which case you get fallthru - you don't need any of those elses. (or is that what the Alternative in Alternative Computing Team is for? )
__________________
Bang head on keyboard to continue... |
|
|
|
|
|
#5 (permalink) |
|
Moderator/Gearhead
|
Thank you stirling. I might see about removing those elses, I was just duplicating from the first line and didn't know better. In my case, I couldn't have a default radio button set. Anyways, this is the code I needed to get it working:
Code:
var x = 0;
for (i=0; i<document.PartsRequest.Equipment_type.length; i++)
{
if (document.PartsRequest.Equipment_type[i].checked)
{
x++;
break;
}
}
if (x == 0)
{
alert('You need to select at least one equipment type');
return false;
} if (document.PartsRequest.Parts.value == "")
__________________
![]() Registered Linux User #435503 Don't let socialists take over this country. Vote Nobama 2008! |
|
|
|
![]() |
| Thread Tools | |
|
|