PDA

View Full Version : How to send 2 or more values in select tag option


tarundhillon
01-23-2005, 11:21 PM
Hi,

I have a select tag in my page.
<select name='abc' id='abc'>
<option value='a1'> A1</option>
</select>

Now i want to send one more attribute in each option, such that it would be accessible in the javascript.

like
<select name='abc' id='abc'>
<option value='a1' valueType='b1'> A1</option>
</select>

Is the above thing possible, if not then how do we send the 2 or more values in select tag option.

One way could be to concat the value and then separate them. But this isn't a good way of sending values.

Any help would be highly appreciated
regards
Tarun Dhillon

Jon Hanlon
01-24-2005, 12:10 AM
Apart from concatenating values, the only thing you can do is put the extra info into a hidden field:

<form...>
<input type="hidden" name="hiddenValueType">
<select name='abc' id='abc' onchange='doValueType(this)'>
<option value='a1' valueType='b1'> A1</option>
</select>
</form>

<script...>
function doValueType(selObj) {
var form = selObj.form;
var option = selObj.options[selObj.selectedIndex];
var valType = option.getAttribute("valueType");
form.hiddenValueType.value = valType;
}
</script>


http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getattribute.asp

tarundhillon
01-27-2005, 06:06 AM
Thanks Jon .. The approach suggest by you is pretty neat..

regards
Tarun Dhillon