When I use jQuery to add an <input>, the new input‘s value gets copied to the page’s preexisting input, whenever the page is refreshed!
Run this page in Firefox:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('<input />').attr({ 'type': 'text' }).val(2).appendTo($('#cart'));
})
</script>
</head>
<body>
<div id="cart">
</div>
<input type="text" id="afe" />
</body>
</html>
When it first loads, the original input will be blank and the input added by jQuery will have a value of 2.
Now press F5. Both inputs will show the value 2!
What’s going on?
It looks like Firefox’s autocomplete is getting confused. Chrome does not do this.
See jsfiddle.net/TAGkR.
After the initial page load, it looks like this in Firefox (15.01):
But refresh the page/iframe and it looks like this!
This is probably a bug in Firefox. Here’s some ways you can work around it:
Set the first input to
autocomplete="off".EG:
<input type="text" id="afe" autocomplete="off" />See this Fiddle.
Have jQuery add the new input physically after the original one.
EG:
See this Fiddle.