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.
Multi Selection Valiation
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Selection/combo boxes will default to the first item if nothing else is selected. Normally the first item is delibrately something like below
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.
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>Hope that is what you meant.
Hi Here is the code
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.
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.
Check
& please use [syntax ][/syntax ] tags to highlight your code.
Code: Select all
if(count($_POST['skillset']) > 0)Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Boy you sure did ask for Javascript. Man I was off yesterday!
Javascript could work like this, but it's untested:
That'll just check if the value exists - you might want to do something more complex & thorough.
Javascript could work like this, but it's untested:
Code: Select all
if(document.getElementById('idOfElement').value)
{
...
}Real programmers don't comment their code. If it was hard to write, it should be hard to understand.