homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Trying to clean up my code of "Warnings"
LinuxGold




msg:1490165
 2:06 pm on Nov 3, 2005 (gmt 0)

I'm trying to learn JavaScript and at same time trying to make it W3C standard. That way I will develop a good habit in creating a validable web pages. I'm trying to figure out how to fix this code:

if(krono_process.assocID.options[0].selected)
{
..
}

When I opened JavaScript Console in firefox, I get the error:

Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.

And my form looks like this:

<form action="khours.asp" method="post" name="krono_process" onsubmit="return validateKronos(this);" autocomplete="off">
..
</form>

Oh, one more thing -- 'autocomplete="off"' isn't validated, what is the alternative for it? This web page will be used for data entry and I do not want autocomplete to interfer their operations.

 

Bernard Marx




msg:1490166
 2:53 pm on Nov 3, 2005 (gmt 0)

Using full W3C standard script to get a select element's selection is tricky, and probably involves some messing about to get all browsers to conform. I'll have to look deeper sometime. The warning isn't necessarily about not using fully W3C DOM1 interface code, it's just that you are relying on using the form's name as a global reference.

Either of these 2 statements should make the warning go away:

a) Using older, "document collections", code:

You have sent a ref to the form to the function:

onsubmit="return validateKronos(this);"

Let's assume that you have this:

function validateKronos(form)

Then:

if( form.elements.assocID.options[0].selected )

b) A mixture of older and newer code

if( document.getElementsByName('assocID')[0].getElementsByTagName('option')[0].selected)

------------------
RE: autocomplete

Either
a) Write a new DTD for your document
b) Simply ignore validator warnings about this particular invalid attribute. Browsers don't validate documents anyway.

LinuxGold




msg:1490167
 3:12 pm on Nov 3, 2005 (gmt 0)

Hmm.. DTD -- I would like to learn that. Where can I get started for that part?

I already changed my document to conform your a. part suggestion, at least for now. I'm using Firefox, IE (all versions), Opera and lynx (paramount important) to test my application development. Warning went away except for document part.

Bernard Marx




msg:1490168
 3:32 pm on Nov 3, 2005 (gmt 0)

Don't know much about DTD's. Considering browsers don't generally download DTDs anyway, it seems a bit pedantic. Yet, if you like, there are a few texts on it:

[google.se...]
[google.se...]

In XHTML 1.1 one should be able to add a small module.

Warning went away except for document part.

?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved