The code works fine for me, but what I'm trying to do is add an additional condition to it. Currently, I just have the code set up to check if the user has enter their name, email, and phone number. But I also need it to validate something else only if a specific condition is true. On my form I have 2 different sets of Radio lists. One is called Function and the other radio list is called Design. If the user selects an option on one of the 2 lists, then it will be required for the user to also select an option from the 2nd list. The user CAN decide not to select anything from either radio list, but can not select from one list and NOT from the other.
This is the If statement that I created (don't know if its correct or how to insert it to my current validation code).
Code:
<script type="text/javascript">
if (Function+Design<1 or == 400 or == 800)
{document.write("Please select both a Function and Design Type");}
</script>
I need it in JavaScript, not PHP. My actual form page is in HTML, so I'm using JavaScript to validate fields on the form. After the data has pass the validation process it does then go to a PHP file. I do not need help with my PHP file, that works fine for me. What I need help with is the JavaScript code that I have on my HTML file where my form is located. Please go to the URL that I placed on my original post, so you can see the JavaScript code that I am working with.
var functionList = document.getElementById('myform').Function;;
var designList = document.getElementById('myform').Design;
var functionChecked = false;
var designChecked = false;
for(var i = 0; i < functionList.length; i++)
{
if(functionList[i].checked){
functionChecked = true;
break;
}
}
for(i = 0; i < designList.length; i++)
{
if(designList[i].checked){
designChecked = true;
break;
}
}
//if at least one was checked and one was not checked (equivalent to ONLY one group was checked)
if( (functionChecked || designChecked) && (!functionChecked || !designChecked) )
{
alert('You need to choose something from the ' + (!functionChecked? 'Function' : 'Design') + ' radio group.');
}
Hopefully you can figure out where this code will go in order to do your validation... and obviously change the alert() to your preferred method of messaging the user.
Here is my current code and the colored section is my current form validation code. I need to know how to change my current validation code to include the Radio lists validation option.
Do yourself a *BIG* favor and stop using DumbWhacker for doing validation. DoofusWhomper (oh, okay, DreamWeaver) produces perhaps the worst (and most ancient!) JavaScript code of any tool out there.
DW's email validation code is so weak that it accepts an email address of (for example) "x@y" or even " @ ". And for ordinary text fields, it accepts even a single space as valid.
It's just plain worthless validation.
Almost any validator you find online will be better than that. And the good ones can be really quite good.
SkyChan's basic code for validating radio buttons and/or requiring at least one of a group of checkboxes to be checked is okay, but it really ought to be converted into a function. And should be modified to handle the case of single checkboxes, too.
I could rewrite the entire validation for you, but I think you should do some basic research first. You might well find a *good* validator that will do all you want.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.