View Full Version : <input type=text... ?
peterinwa
03-18-2003, 05:17 AM
Why does the following only put "search" into the text field rather than "search text"
It seems to stop at the space.
var ST="search text";
c="<input type=text name=search value="+ST+" size=25 maxlength=25 border=1>";
document.write(c);
</script>
Graeme Hackston
03-18-2003, 05:39 AM
<script>
var ST="search text";
c="<input type='text' name='search' value='"+ST+"' size='25' maxlength='25' border='1'>";
document.write(c);
</script>
peterinwa
03-18-2003, 05:44 AM
Thanks, works great. Though I can't see why it's needed.
Also with both HTML and JS I've never put quote marks around numbers and never had a problem. ???
Graeme Hackston
03-18-2003, 05:49 AM
I haven't got JS to work inserting a variable without quotes. The numbers might not need it but it's a habit now :)
glenngv
03-18-2003, 08:41 AM
if you didn't put the quotes, the output would be like this:
<input type=text name=search value=search text size=25 maxlength=25 border=1>
obviously, the value would only be search since there is no quotes, text will be treated as an attribute name with no value, which will be ignored. it's always a good habit to put double quotes even if the attribute value doesn't have spaces, especially if you will make it XHTML compatible.
Graeme Hackston
03-18-2003, 10:25 PM
Glen you're a good teacher. It's obvious now.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.