pman
06-15-2007, 12:47 AM
Hey guys,
Here's another unusual problem. If you just try the following you will see that there is text box and button beside it. The text box has a default value.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Input value test</title>
</head>
<body id="page1Body">
<script type="text/javascript">
var searchInput = document.createElement("input") ;
searchInput.id = "search" ;
searchInput.type = "text" ;
searchInput.value = "Enter a query" ;
searchInput.size = 40 ;
var searchSubmit = document.createElement("input") ;
searchSubmit.id = "btnSearch" ;
searchSubmit.type = "button" ;
searchSubmit.value = "Search" ;
document.getElementById("page1Body").appendChild(searchInput) ;
document.getElementById("page1Body").appendChild(searchSubmit) ;
</script>
</body>
</html>
So far so good. But since the submit button is too close to the textbox, I did the following after adding the textbox so that there's some space between them, and then appended the submit button.
document.getElementById("page1Body").innerHTML += " " ;
And surprisingly, the text value disappears from the text box. It's happening in both Firefox and Opera. Somehow, IE is okay.:confused:
Any idea what's going on? I know I could just use the innerHTML to add the entire text box and the submit button, but I want to use what I have right now, just because it's more cleaner. Thanks for your help.
Here's another unusual problem. If you just try the following you will see that there is text box and button beside it. The text box has a default value.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Input value test</title>
</head>
<body id="page1Body">
<script type="text/javascript">
var searchInput = document.createElement("input") ;
searchInput.id = "search" ;
searchInput.type = "text" ;
searchInput.value = "Enter a query" ;
searchInput.size = 40 ;
var searchSubmit = document.createElement("input") ;
searchSubmit.id = "btnSearch" ;
searchSubmit.type = "button" ;
searchSubmit.value = "Search" ;
document.getElementById("page1Body").appendChild(searchInput) ;
document.getElementById("page1Body").appendChild(searchSubmit) ;
</script>
</body>
</html>
So far so good. But since the submit button is too close to the textbox, I did the following after adding the textbox so that there's some space between them, and then appended the submit button.
document.getElementById("page1Body").innerHTML += " " ;
And surprisingly, the text value disappears from the text box. It's happening in both Firefox and Opera. Somehow, IE is okay.:confused:
Any idea what's going on? I know I could just use the innerHTML to add the entire text box and the submit button, but I want to use what I have right now, just because it's more cleaner. Thanks for your help.