tags:

views:

34

answers:

3

Before:

<select id="NumberId" name="NumberId">
  <option value="">ZERO</option>
  <option value="4">FOUR</option>
  <option value="5">FIVE</option>
</select>

Using JQuery, modify the value of the option with an empty value to 0 (zero).

After:

<select id="NumberId" name="NumberId">
  <option value="0">ZERO</option>
  <option value="4">FOUR</option>
  <option value="5">FIVE</option>
</select>

How can I do that?

+2  A: 

I think you can do something like:

$("#NumberId option[value='']").val('0');

good luck

Paul
+1  A: 

Well you can do something like this:

$("#NumberId option[value='']").attr("value", "0");

or

$("#NumberId option[value='']").val("0");

(not 100% sure that works with <option> elements)

But the more obvious thing to do is correctly generate the HTML on the serverside, no?

cletus
I agree - but in this case, I did not have the option of editing the selectlist source of this serverside, unfortunately.
Kjensen
+1  A: 
$("select option[value='']").attr("value", "0");
Dominic Rodger