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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
Thread Tools
Old 01-27-2007, 06:52 PM   #1 (permalink)
K-B
Moderator/Gearhead
 
K-B's Avatar
 
Join Date: Oct 2005
Location: NY
Posts: 2,738
OS: Ubuntu 8.04

My System

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.
K-B is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 01-28-2007, 06:35 AM   #2 (permalink)
K-B
Moderator/Gearhead
 
K-B's Avatar
 
Join Date: Oct 2005
Location: NY
Posts: 2,738
OS: Ubuntu 8.04

My System

Ok, I figured out part of the problem.
Quote:
} else if(document.PartsRequest.Equipment_type.value.length < 1) {
alert("Please enter a equipment type.");
document.PartsRequest.Equipmenttype.focus();
return;
The problem with that command is that that particular field is radio buttons, not text boxes. I removed it, and the rest works, & the button works, but now I need to figure out what the code is to require one radio button selected. Anyone know?
__________________

Registered Linux User #435503

Don't let socialists take over this country. Vote Nobama 2008!
K-B is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 01-29-2007, 02:26 AM   #3 (permalink)
Design Team Member
 
KoosHopeloos's Avatar
 
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
__________________
KoosHopeloos, straight to you from .nl via the world wide web (but on sabbatical)!

Website for free: to code/design KompoZer, for graphics Paint.NET or GIMP, and to upload CoreFTP

KoosHopeloos is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 01-31-2007, 06:44 AM   #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...
stirling is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 01-31-2007, 07:18 PM   #5 (permalink)
K-B
Moderator/Gearhead
 
K-B's Avatar
 
Join Date: Oct 2005
Location: NY
Posts: 2,738
OS: Ubuntu 8.04

My System

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!
K-B is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

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

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



All times are GMT -7. The time now is 06:58 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82