Could you please explain the error a little more as what you posted doesn’t help as to where the error is occurring, on another note the code above is very redundant as your chaining a lot of your attr methods which can be merged into one method with an object as the value. See the below code which is a little longer but is more efficient:
function saveloc(postcode, display, mode, type)
{
if (mode == 2)
{
if (type == 'postcode')
{
var id = 'pc_hidden',
name = 'postcode',
val = postcode;
}
else
{
var id = 'country_hidden',
name = 'country',
val = display;
}
$('<input />', {
id : id,
type : 'hidden',
name : name,
'class' : 'savedloc'
}).val(val)
.appendTo('#saved_locations');
$('#location_ajax_search').val(display);
$('#location_results').hide();
$('#location_ajax').val('');
}
else
{
var hiddenfields = $('.savedloc').length;
if ($('#pc_hidden_' + postcode).length)
{
alert('You have already selected this postal area.');
$('#location_results').hide();
$('#location_ajax').val('');
return false;
}
if (hiddenfields < 5)
{
$('<input />', {
id : 'pc_hidden' + postcode,
type : 'hidden',
name : 'location[]',
'class' : 'savedloc'
}).val(postcode)
.appendTo('#saved_locations');
$('<input />', {
id : 'pc_html' + postcode,
type : 'hidden',
name : 'display_location[]',
'class' : 'savedloc'
}).val([postcode, display].join('|'))
.appendTo('#saved_locations_html');
$('#saved_locations_html').append(
'<div class="sl_block" id="pc_display_' + postcode + '">' + display + ' <a onclick="removeloc(\\'' + postcode + '\\')">(remove)</a></div>'
);
$('#location_results').hide();
$('#location_ajax').val('');
}
else
{
alert('You can only add a maximum of 5 locations.');
$('#location_results').hide();
$('#location_ajax').val('');
return false;
}
}
}
Yes that is correct, IE doesn’t allow that. At least legacy IE doesn’t, I haven’t tried it in newer versions yet.
The way around this is to create a new input element and copy the values you need fro the original element to the new one, and then remove the old one.
The above code is actually creating input elements on the page, I’m aware of the IE issues surrounding input types which I more then likely would have explained if the code were trying to change the type attribute.