[thelist] Javascript: url variable to form text field

Hassan Schroeder hassan at webtuitive.com
Thu Mar 13 18:24:49 CST 2003


Joshua Olson wrote:

> The document.write should be used to
> output the ENTIRE input tag as it is not possible to put a tag within a tag.
> I'm surprised nobody else mentioned this!
> 
> So, something like this:
> 
> <script language="JavaScript" type="text/javascript">
>   document.write('<input type="text" value="' + url["foo"] + '" />');
> </script>

Uh, except then there's no input field at all if someone has JS
turned off, and even with JS this kind of construction is more
difficult to maintain (like -- you decide to add a class to that
input later, need to change the element name, etc.).

Why not just:

   <input type="text" name="urlVariable" />

with something like this in the document head:

<script type="text/javascript">
function setInput()
{
	document.forms[0].urlVariable.value = url["foo"};
}
window.onload=setInput;
</script>

Just a suggestion...
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.





More information about the thelist mailing list