M
Matt Kruse
According to standards, if an option is selected and it has no VALUE
attribute, the contents of the option tag is to be submitted.
So:
<select name="sel">
<option selected>Value</option>
</select>
will submit as "sel=Value".
Unfortunately, IE says that sel.options[sel.selectedIndex].value == "",
whereas FF reports "Value".
So how can script accurately extract the value that will actually be
submitted?
I have written this code, which works:
function optionValue(opt) {
if (opt.value!="") {
return opt.value;
}
if (!'value' in opt) {
return opt.text;
}
if (opt.outerHTML && opt.outerHTML.test(/<[^>]+value\s*=/i)) {
return opt.value;
}
return opt.text;
}
String.prototype.test=function(regex) {
return regex.test(this);
}
Suggestions?
attribute, the contents of the option tag is to be submitted.
So:
<select name="sel">
<option selected>Value</option>
</select>
will submit as "sel=Value".
Unfortunately, IE says that sel.options[sel.selectedIndex].value == "",
whereas FF reports "Value".
So how can script accurately extract the value that will actually be
submitted?
I have written this code, which works:
function optionValue(opt) {
if (opt.value!="") {
return opt.value;
}
if (!'value' in opt) {
return opt.text;
}
if (opt.outerHTML && opt.outerHTML.test(/<[^>]+value\s*=/i)) {
return opt.value;
}
return opt.text;
}
String.prototype.test=function(regex) {
return regex.test(this);
}
Suggestions?