Multi Selection Valiation

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Multi Selection Valiation

Post by dharprog »

Hi

I'm using a multiple selection box. But my problem is how to validate that is selected or not? i"m unable to find out the solution for this.

If anybody come across to this please tell me.

Thank You very much.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You validate your select box like any other input.. :?

Post what your trying to do, maybe it will shed some light on what your having difficulties with.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Selection/combo boxes will default to the first item if nothing else is selected. Normally the first item is delibrately something like below

Code: Select all

<select name="mysel">
  <option value="0">Please Select....</option>
  <option value="1">Option1</option>
  <option value="2">Option2</option>
  <option value="3">Option3</option>
</select>
Using the above HTML, by default the $_POST['mysel'] or $_GET['mysel'] (depends on the form) will return the first option value (in this case 0) if the user doesn't do anything. You can then use (empty to test if the user has a value.

Hope that is what you meant.
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Hi Here is the code

Post by dharprog »

Hi

NOt that one.

The code is like this

<select name="skillset[]" class="ccpsComboBox" multiple="multiple">
<? $str = get_table("categories"); while($row = mysql_fetch_array($str)){ ?>
<option value="<?=$row[cat_name]?>"><?=$row[cat_name]?></option>
<? }?>
</select>

You can test this one so that you could understand. I'm not getting the validation for this multiple selection.

Thank you very much.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Check

Code: Select all

if(count($_POST['skillset']) > 0)
& please use [syntax ][/syntax ] tags to highlight your code.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Hi

Post by dharprog »

Hi Pickle,

Fine thank you for the information but i'm asking how to validate that in javascript in the client side itself. Not in php.

Thank YOU.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Boy you sure did ask for Javascript. Man I was off yesterday!

Javascript could work like this, but it's untested:

Code: Select all

if(document.getElementById('idOfElement').value)
{
...
}
That'll just check if the value exists - you might want to do something more complex & thorough.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply