G
gkelly
Can someone explain what I am doing wrong, or why this will not work?
I've tested this in IE6, Firefox 1.5 and Mozilla 1.7, all with the same
result.
Take for example this code:
<html>
<head>
<script>
function replace(){
var obj = document.getElementById('textbox');
obj.setAttribute('value','This is the replaced text');
}
</script>
</head>
<body>
<a href="javascript:void(0)" onClick="replace();">replace</a>
<input type="text" id="textbox" name="textbox" value="">
</body>
</html>
If you load this in a webpage and click on 'replace', the input box
will be filled with "This is the replaced text", as expected. Now click
in the input box and delete a few letters, or the entire text, and
subsequent clicks on 'replace' will have no affect to the value in the
input box.
I've tried using obj.value = 'This is the replaced text', but this
method doesn't work in Mozilla.
Is there a reason setAttribute('value',var) will only work if the input
box has yet to be edited manually?
I've tested this in IE6, Firefox 1.5 and Mozilla 1.7, all with the same
result.
Take for example this code:
<html>
<head>
<script>
function replace(){
var obj = document.getElementById('textbox');
obj.setAttribute('value','This is the replaced text');
}
</script>
</head>
<body>
<a href="javascript:void(0)" onClick="replace();">replace</a>
<input type="text" id="textbox" name="textbox" value="">
</body>
</html>
If you load this in a webpage and click on 'replace', the input box
will be filled with "This is the replaced text", as expected. Now click
in the input box and delete a few letters, or the entire text, and
subsequent clicks on 'replace' will have no affect to the value in the
input box.
I've tried using obj.value = 'This is the replaced text', but this
method doesn't work in Mozilla.
Is there a reason setAttribute('value',var) will only work if the input
box has yet to be edited manually?