Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-18-2008, 02:45 PM
Member
 
Join Date: Nov 2007
Posts: 30
Exclamation form validation

Ok, this is not really a php question, but I could not find any javascript forums so........Basically I've been doing an online survey. And I'm using javascript to validate form input. I'm aware of how to check radios and dropdowns and thats all fine....My problem is for one question I want the user to pick a few answers from a wide selection of dropdowns, but not force them to pick all of them.

this is my usual script

if ( document.form1.e46.selectedIndex == 0 )
{

alert ( "Please answer all questions before continuing!" )
return(false);
}

But obviously if I use that for all the dropdowns then they will have to answer all of them. I need to get them to answer at least one dropdown basically, then they can continue....Any of you kind folks know a bit of java?
Reply With Quote
  #2 (permalink)  
Old 03-18-2008, 10:10 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

Umm js isn't my forte but couldn't you use some kind of population method?
javascript.internet.com/forms/dropdown-box-population.html

I use spry for validation where it writes the js for me. I also use php to validate certain criteria
__________________
West Dorset Community
Reply With Quote
  #3 (permalink)  
Old 03-19-2008, 09:19 AM
Member
 
Join Date: Nov 2007
Posts: 30
Default

What is spry? Yeah I've looked at the link you provided. Its not quite what I'm after. thats the problem if you have not learned javascript. You can't just throw it together and hope it works. Because you've got no idea how to write it...
Reply With Quote
  #4 (permalink)  
Old 03-19-2008, 09:44 AM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

Spry is a set of js libraries already built and easy to implement.
labs.adobe.com/technologies/spry

Am sure there are folk on here good at js so you will probably get an answer sooner or later..........

As mentioned, you could use php. If it were a few dropdown menus and only one need to be filled in then you would create an array of dropdowns, then check if that array is empty or not. But js maybe your prefered option
__________________
West Dorset Community
Reply With Quote
  #5 (permalink)  
Old 03-19-2008, 09:57 AM
Member
 
Join Date: Nov 2007
Posts: 30
Default

Both are equally perplexing to a noob like me unfortunately... Basically the problem is that there are mutiple product categories, and below each product are 8 dropdowns which rate a function of the product (so 5 columns each with 8 dropdowns below). So I have to force the user to choose at least one drop down, then continue to fill in all the 8 categories for that product. But not all products. Only those that apply... So I dont have one exact dropdown I can validate. They have a choice. I found this code

var sel = document.forms[0].elements["selectName"];
var fld = document.forms[0].elements["textboxName"];
if(sel.selectedIndex == 1
&& /^\s*$/.test(fld.value)) {
alert("Comments required when option 2 selected.");
fld.select();
fld.focus();
return false;
}

I think I may be looking at something similar...Basically if the user has selected one dropdown from a category then they need to continue with the rest...Ignore the names on the script....But that sort of idea with dropdowns

Last edited by shaunlevett; 03-19-2008 at 10:05 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:48 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum