Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Validate a form and make sure a user chosses a radio button if they've selected 'yes' to the previous question.

Posted on 2004-11-17
3
Medium Priority
?
209 Views
Last Modified: 2012-08-13
I've got a form on a page which is quite big. For speed's sake, I've used Yaromat's dreamweaver extension to validate the form - and it does a good job, however, I need to alert the user if choose 'yes' to one question but then don't select an answer to another question.

First Question:

"Are you currently using the software?"
Yes
 <input type="radio" name="q1software" value="Yes" >

No
<input type="radio" name="q1software" value="No" >

Second question:

"If so, what version?"

V9
<input type="radio" name="q1version" value="V9" >
V8

<input type="radio" name="q1version" value="V8" >

Other

<input type="radio" name="q1version" value="Other" >


If the user chooses 'Yes' in the first question, they need to then choose something from the next bit.

Any ideas?

Also, it needs to sit alongside the existing javascript entry, can I call two javascript functions from the same submit button?
0
Comment
Question by:andycal
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
p_partha earned 1000 total points
ID: 12605419
check this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<script>
function partha()
{
firstval = checkControl("q1software")
if (firstval=="Yes")
{
secondval = checkControl("q1version")
if (secondval=="")
{
alert('you have to select second option')
return false
}
}
}
function checkControl(strFieldName){
    var objFormField = document.forms[0].elements[strFieldName]
    intControlLength = objFormField.length
    bolSelected = false;
    for (i=0;i<intControlLength;i++){
         if(objFormField[i].checked){
                   bolSelected = true;
                   break;
         }
    }    
     if (!bolSelected)
             return ""
         return objFormField[i].value
   
}





</script>
<title>Untitled</title>
</head>
<body >
<form>
"Are you currently using the software?"
Yes
<input type="radio" name="q1software" value="Yes" >


<input type="radio" name="q1software" value="No" >
"If so, what version?"

V9
<input type="radio" name="q1version" value="V9" >
V8

<input type="radio" name="q1version" value="V8" >

Other

<input type="radio" name="q1version" value="Other" >


<input type='button' onclick='partha()'>
</form>
</body>
</html>
0
 

Author Comment

by:andycal
ID: 12605631
Thankyou, thankyou, thanyou, sorted, customer happy!

Plus you made me laugh with the BoSelected var.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 12605654
Thanks for the points, I had teh function for checkbox picked from this forum, i just changed it to ur need

Partha
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question