[thelist] Tip: Converting to XHTML, javascript, name, id

One Happy huimaozi at brain.com.pk
Sun Aug 25 20:41:01 CDT 2002


Hey,why have you send me so many letters?And I just registered a free web host.If you would not give me the web host,plez just tell me and do not send me letters any more.Thax.

On Sunday, August 25, 2002 at 07:37:57 AM, thelist at lists.evolt.org wrote:

>
> <tip type="Converting to XHTML, javascript, name, id" author="Frank Marion">
>
> If you are converting your site or apps over to strict XHTML
> 1.0, you'll find that using the "name" attribute will raise
> the validator's danders. You're doing simple error checking or
> roll-overs via Javascript. So now you've got to use ID instead
> of name. What do you do? What *do* you do?
>
> Simple. Remember that every identified item in a document
> must have a *unique* id. Remove the name, replace it with an
> ID.
>
> We change this:
>
>    <input type="text"
>           name="yourFieldName"
>           value="Enter search keywords" />
> to:
>
>    <input type="text"
>           id="yourFieldName"
>           value="Enter search keywords" />
>
> "You evil villain!", you exclaim, "This breaks my
> javascript!" (Startled, Frank stops twisting his mustachio).
> No problem. The adjustment to your script is quite minimal.
>
> We change this:
>
>    yourFormName.yourFieldName.value.length == 0
>
> to:
>
>    document.getElementById('yourFieldName')
>
> That's it.
>
> Some notes: You can make your code a little terser (shorter,
> and most likely easier to read and type) by setting the field's
> id to a variable, and simply referring to the variable's name
> throughout your script instead of using the full declaration
> all the way though.
>
> Instead of:
>
>    if (document.getElementById('yourFieldName').value
>          == 'Enter search keywords')
>
> You can do this:
>
>  Declare your variable before you start
>
>    var theField = document.getElementById('yourFieldName');
>
> then use this:
>
>    if (theField.value == 'Enter search keywords')
>
> Hope this helps.
>
> </tip>
>
>
> --
> Frank Marion,
> framar at interlog.com
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>
>

One  Happy
e-mail: huimaozi at brain.com.pk

*------------------------------------------------------------------------------*
Brought to you by Brain Net, The Largest ISP of Pakistan. www.brain.net.pk
*------------------------------------------------------------------------------*




More information about the thelist mailing list