This is a weird issue, it works in IE but it doesn’t in Firefox.
I have a SELECT control that when get focus, retrieve the HTML with the OPTIONs in an AJAX call.
The onfocus event handler contains this code:
var selectedValue = $(":input[name='" + fieldName + "']").val();
var dataRetrieved = function(data)
{
$(":input[name='" + fieldName + "']").html(data);
$(":input[name='" + fieldName + "']").val(selectedValue);
alert("data: " + data);
alert("former value: " + selectedValue);
};
$.post(url, data, dataRetrieved);
The first alert shows:
data: <option value=""/>
<option value="1" >a1</option>
<option value="2" >a2</option>
<option value="3" >a3</option>
And the second:
former value: 3
So it should work, actually it does in Internet Explorer (what make me think I’m doing something wrong about the HTML)
Any idea about what could be the problem?
Thanks.
The input selector does not need a colon before it. Your selector should look like this:
not
That’s my first guess as to why it might not be working.