[thelist] Javascript: url variable to form text field

Joshua Olson joshua at waetech.com
Thu Mar 13 21:11:35 CST 2003


----- Original Message -----
From: "Hassan Schroeder" <hassan at webtuitive.com>
Sent: Thursday, March 13, 2003 7:24 PM


> 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...

And a good suggestion.  I was commenting on Tom's original comment without
trying to really provide a "better" solution.  It all kinda swirled out of
control at that point as we suggested fixes to a technique that was
inherently flawed already.  Of course you are correct.

<tip type="HTML and JS Integration" author="Joshua Olson">
One "best practice" is to make sure that a page will work perfectly as pure
HTML first, then add JS only to enhance it's pure HTML functionality.  This
will ensure that the code will work on browsers with and without JavaScript.
</tip>

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168



More information about the thelist mailing list