korkus2000

msg:1480944 | 8:52 pm on May 3, 2003 (gmt 0) |
It is possible. Are you using radio buttons or check boxes?
|
ladyshanae

msg:1480945 | 9:07 pm on May 3, 2003 (gmt 0) |
I'm currently using drop down menus, but I was using radio buttons before.
|
korkus2000

msg:1480946 | 10:22 pm on May 3, 2003 (gmt 0) |
Drop downs that have a yes and no option?
|
ladyshanae

msg:1480947 | 10:31 pm on May 3, 2003 (gmt 0) |
Yes, they have a Select One, Yes, and No options. But if it is easier to use radio buttons or check boxes, I can change it :)
|
korkus2000

msg:1480948 | 10:49 pm on May 3, 2003 (gmt 0) |
You can use a script like this: <script language="JavaScript"> function checkSelects() { //set a variable to hold the string info var selectedNo = ""; //test the select boxes for their values if (document.nameOfForm.NameOfDropDown1.options[document.nameOfForm.NameOfDropDown1.selectedIndex].value!= "yes") { //If they are not equal to yes then add the text for the alert box of which //select box is not equal to yes. selectedNo += "\n - People"; } if(document.nameOfForm.NameOfDropDown2.options[document.nameOfForm.NameOfDropDown2.selectedIndex].value!= "yes") { selectedNo += "\n - Places"; } if (document.nameOfForm.NameOfDropDown3.options[document.nameOfForm.NameOfDropDown3.selectedIndex].value!= "yes") { selectedNo += "\n - Things"; } //test to see if you have any string info in the variable if (selectedNo!= "") { //If so write an alert box telling which hasn't been selected to yes selectedNo ="_____________________________\n" + "You select no for:\n" + selectedNo + "\n_____________________________" + //Explain why you don't want these people submiting "\nWe don't like negative people!\nSo we don't want you to submit\nyour form!"; alert(selectedNo); //Stop the submit from going through return false; } //No "no"s so let them submit. else return true; } </script> If you are not looking to tell the user anything then you could always do this: <script language="JavaScript"> function checkSelects() { //set a variable to hold the string info var selectedNo = ""; //test the select boxes for their values if (document.nameOfForm.NameOfDropDown1.options[document.nameOfForm.NameOfDropDown1.selectedIndex].value!= "yes") { //If they are not equal to yes then add the text for the alert box of which //select box is not equal to yes. selectedNo += "\n - People"; } if(document.nameOfForm.NameOfDropDown2.options[document.nameOfForm.NameOfDropDown2.selectedIndex].value!= "yes") { selectedNo += "\n - Places"; } if (document.nameOfForm.NameOfDropDown3.options[document.nameOfForm.NameOfDropDown3.selectedIndex].value!= "yes") { selectedNo += "\n - Things"; } //test to see if you have any string info in the variable if (selectedNo!= "") { //Stop the submit from going through return false; } //No "no"s so let them submit. else return true; } </script> For the form it would look like this. Notice the onSubmit attribute in the opening form tag. It calls the function above. Make sure all names of the form and dropdowns are correct in the above function. You also need a submit button to fire off the onSubmit event. <form name="nameOfForm" onSubmit="checkSelects()"> Do You Like People? <select name="NameOfDropDown1"> <option value="no">No</option> <option value="yes">Yes</option> </select><br> Do you like Places? <select name="NameOfDropDown2"> <option value="no">No</option> <option value="yes">Yes</option> </select><br> Do You Like Things? <select name="NameOfDropDown3"> <option value="no">No</option> <option value="yes">Yes</option> </select> <br> <input type="submit"> </form> BTW Welcome to WebmasterWorld. :)
|
ladyshanae

msg:1480949 | 11:14 pm on May 3, 2003 (gmt 0) |
Thanks very much for the Welcome! One more question...how do I get it to also go to another url on submit, as well as validating the answers? Basically, I want the people who answer all yesses to be directed to another page after submission. The way that I did have it, people were getting directed to the other page no matter what they answered, once they hit the submit button. I really liked the popup that your script gave me when someone answers no. Now I need the people who answer yes to get to go on to the next page. Is that possible?
|
Oaf357

msg:1480950 | 1:32 am on May 4, 2003 (gmt 0) |
Do you have access to PHP?
|
korkus2000

msg:1480951 | 1:46 am on May 4, 2003 (gmt 0) |
So you want to redirect people who answer all yeses and not the nos? If so then I would handle that on the page you are submiting to. If they answer no they won't submit and it won't be a problem. You just set your action attribute in the form tag to the script or page processing the form like: <form name="nameOfForm" onSubmit="checkSelects()" action="pageorscripthandlingform.cgi"> Then let that page or script do the redirect. Like Oaf357 mentioned serverside scripting will handle this much better than JavaScript.
|
ladyshanae

msg:1480952 | 3:46 am on May 4, 2003 (gmt 0) |
I tried that, and it didn't work. When the user selects a no answer, the popup comes up. When they click "ok" on the popup, they are still redirected to the next page, lol. I am building this site for someone else, and I do know that they are going to be running something on there (unrelated to the site) that is ASP...I am not terribly sure if I can use php on this, if they are on a windows server and running ASP? This part is out of my league...all I am doing it building the plain, old fashioned html site, lol. That's why I wanted to use java script to do the validate/redirect if I could.
|
MWpro

msg:1480953 | 4:27 am on May 4, 2003 (gmt 0) |
Using php to check if all of them are yes would be a lot easier using php. Where will this form submit to? Email? database? Make a file ending with .php, put this in the file <? phpinfo(); ?> this will check if you have php on your server. If you do then we can help you with a nice php script to handle your problem.
|
DrDoc

msg:1480954 | 4:29 am on May 4, 2003 (gmt 0) |
Then don't use a submit button. Use a regular input button instead: <input type="button" value="Submit" onclick="checkSelects()"> At the end of your JavaScript function (where you end up if they are all "yes") put this: document.name_of_form.submit();
|
ladyshanae

msg:1480955 | 5:10 pm on May 4, 2003 (gmt 0) |
Dr. Doc, that worked! Thank you SOOOOO much! I owe you my eternal gratitude, LOL! :)
|
|