Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>validating form field if radio button is checked

validating form field if radio button is checked

m00nbeast
12-02-2004, 10:38 PM
Hi...

I'm Glenn, a javascripting newbie and I am having difficulties with this issue.

I have a form that makes visible a text field when a specific radio button is checked. That works. Then I validate to see if a radio button is checked before I let the form be submitted. That works.

BUT - I cannot seem to get it to validate the form field that is made visible to see if it has content or at least the proper content when the form is submitted. Can you tell me what I am doing wrong please? :)

I can give more info on what kind of validation I want done if needed, but I think my code speaks for itself

Code follows:

<script language="JavaScript">

function validateForm(){

var radio_choice = false;

for (counter = 0; counter < contact.respond.length; counter++)
{
if (contact.respond[counter].checked)
radio_choice = true;
}

if (!radio_choice)
{
alert("Please Select A way To Get In Contact With You");
return (false);
}


if (document.contact.respond[0].checked)
{
if (document.contact.email == "No account email specified")
{
alert("Please update your email in your account info before submitting this form");
document.contact.email.focus();
return false;
}
}

if (document.contact.respond[1].checked)
{
if (document.contact.email == "")
{
alert("Please enter a phone number that you can be reached at");
document.contact.telephone.focus();
return false;
}
}


return true;
}
</script>


<form name="contact" action="contact_send.asp" Method="post" onSubmit="return validateForm()">

Respond by:

<input type="radio" class="menumain" name="respond" value="email" onClick="document.getElementById('container1').style.visibility='visible';document.getElementById('container2').style.visibility='hidden';"> Email &nbsp;&nbsp;

<input type="radio" class="menumain" name="respond" value="telephone" onClick="document.getElementById('container1').style.visibility='hidden';document.getElementById('container2').style.visibility='visible';"> Telephone

<DIV id="container1">
<input type="text" size="25" class="menumain" name="email" value="<%if session("email") = "" then%>No account email specified<%else%><%=session("email")%><%end if%>" readonly>
</DIV>

<DIV id="container2">
<input type="text" size="25" class="menumain" name="telephone" value="">
</DIV>

<input type="submit" value="Send" class="button"></form>
>_< Please Help me!

m00nbeast
12-02-2004, 11:15 PM
ahh nevermind someone helped me out on another forum

if (document.contact.email == "No account email specified")

needs to be

if (document.contact.email.value == "No account email specified")


and same for the phone one.

i cant believe I left out something so simple

oh well good day to you my friends

hemebond
12-03-2004, 02:13 AM
ahh nevermind someone helped me out on another forumA search of these forums for "validate form" would have return many results.

You should also contain code within vbCode [code] tags.


 

TOP

For more info

setting a minimum size
Auto Preview of Image 
Refresh with a query s
JS Validation obsolete
Javascript Pop up func
Slide show transitions
I'm a newbie...please!
how to write coding in
Advanced Debug Info 
.js file doesn't work 

News Archive

Adding Graphic To Text
re-direct form after s
pop up window controls
Clock on homepage - He
passing a param from a
Password Procection wi
document.title in same
focus onload 
Counting Wrong from Ri
Help needed on how to 

Related stories:

Command Buttons & Text Field Data Entry?
Question- Please HELP !
how do you create a pop-up window?
window.back() Fails in IE
Querying a page without reloading current page
document.write browser specific response
button value not being sent

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics