SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast gillian's Avatar
    Join Date
    Oct 2005
    Location
    Scotland
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Having a blonde moment...

    Hi

    Just added abit of validation into a form.

    Code:
    <script language="javascript" type="text/javascript">
    	<!-- hide from old browsers
    	
    	function validForm(form){
    		if (form.username.value == ""){
    		alert("You must enter a username")	
    
                    form.username.focus()
    		return false
    		}
    		if (form.password.value == ""){
    		alert("You must enter a password")
    		form.password.focus()
    		return false
    		}
    	return false
    	}
    	
    	//--stop hiding from old browsers -->
    </script>
    Code:
    <table width="185" height="185" background="Includes/Images/box.jpg">
    
    <tr><td>
    <form action="check_user.asp" method="post" onsubmit="return validForm(this)">
    
    <table width="155" height="140" border="0" align="center">
    
    <tr><td align="left">Username
    <br><input type="text" name="username">
    </td></tr>
    
    <tr><td align="left">Password
    <br><input type="password" name="password">
    </td></tr>
    
    <tr><td align="right">
    <input type="submit" value="Submit">
    </td></tr>
    
    </table>
    
    </form></td></tr>
    </table>
    and now when the details are correct the form will not submit to the specified page.
    What have i missed out? Completely being a blonde here.

    Thanks,
    gillian

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should the last 'return' be 'true'?

    Currently, you always return false

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    And you don't really need the "hide from old browsers" stuff now that it's 2008. This would be especially true if you put the javascript in a separate file, which is always a good idea.

  4. #4
    SitePoint Enthusiast gillian's Avatar
    Join Date
    Oct 2005
    Location
    Scotland
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by r51 View Post
    Should the last 'return' be 'true'?

    Currently, you always return false
    haha cant believe i never noticed that. your a star!!
    thanks,
    gillian

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Raffles View Post
    And you don't really need the "hide from old browsers" stuff now that it's 2008. This would be especially true if you put the javascript in a separate file, which is always a good idea.
    Spot on Raffles. The comment technique to hide javascript from old browsers was for Netscape 1, which didn't understand javascript or the script tag. When Netscape 2 came out in 1995 the comments were a useful way to prevent Netscape 1 from having problems with inline scripts.

    That technique can now be dispensed of.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    Spot on Raffles. The comment technique to hide javascript from old browsers was for Netscape 1, which didn't understand javascript or the script tag. When Netscape 2 came out in 1995 the comments were a useful way to prevent Netscape 1 from having problems with inline scripts.

    That technique can now be dispensed of.
    Yeah, funny how that stuff lingers on. The language attribute another ancient artefact. And since there is no official mime-type for javascript, and since it's the only scripting language supported by browsers (unless you count exotic Microsoft experiments), the type is redundant.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Yeah, we're all using

    Code HTML4Strict:
    <script type="text/javscript">

    when we could be using just

    Code HTML4Strict:
    <script>

    Is it worthwhile doing just this and facing up to question of "but where's the type?"
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Could the same be said about the <style> tag then? I've never heard of any other mime type than text/css.

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    While it's possible to go without the type attribute for both script and style tags, it's still a required attribute according to the specifications, so it's best to stay with them for now.

    http://www.w3.org/TR/html401/interac....html#h-18.2.1
    http://www.w3.org/TR/html401/present....html#h-14.2.3
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh what we do to please the validator!

  11. #11
    SitePoint Evangelist asprookie's Avatar
    Join Date
    May 2005
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's a blonde moment?

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    It's not about pleasing the validator and I'm pretty sure that you know it too.
    It's about standards. I want to see test cases of major situations (and many minor ones) showing how well they respond to the lack of the type attribute.

    For example, XML has no default scripting language, so for that you must specify the type. There are some situations where you can leave it out, and others where you must have it.

    This is why a best-practice policy is to maintain its usage.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by asprookie View Post
    What's a blonde moment?
    http://www.urbandictionary.com/defin...=blonde+moment

    The type tag, imho, should be definitely included; especially for future compatibility.

    The correct mime type for javascript is application/javascript which IE (big surprise) doesn't seem to support.

  14. #14
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The type attribute of the <style> tag, is different. There is an official, and recognised, mimetype to use for style sheets, so it should be specified.
    For <script> though, you need to specify a non-standard mimetype, if you want it to work in IE, so you really only have the choice between breaking the standard in one way or the other. All considered, I guess I prefer the non-standard type="text/javascript", over omitting the type-attribute. But it's not really the correct thing to do, according to the standards.

  15. #15
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another thing, if you have js in a page (not external) the validator will go through it and if you have something like & it will complain. You can either put comments around it (per first post) or - what I think is better (but could be mistaken) - :

    HTML Code:
    <script type="text/javascript">
    // <![CDATA[
    code, code, code, and more code
    // ]]>
    </script>
    HTML Code:
    <script type="text/javascript">
    //the validator will complain about this line &&&&&&&&&&&
    </script>
    @ #10:

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    All considered, I guess I prefer the non-standard type="text/javascript", over omitting the type-attribute. But it's not really the correct thing to do, according to the standards.
    Which standards are we talking about here?

    It's correct according to the HTML 4.01 standards
    http://www.w3.org/TR/html401/interact/scripts.html

    XHTML also uses text/javascript as of 2002
    http://www.w3.org/TR/xhtml1/#h-4.8

    But more recently in 2006 text/javascript is obsoleted for application/javascript
    http://tools.ietf.org/html/rfc4329

    Internet Explorer 6 doesn't understand application/javascript and ignores the code completely.

    So you have a choice of
    [LIST][*]text/javascript which is in the specs but as since been obseleted[*]application/javascript which is the preferred way but breaks IE6[*]no type at all, which work across the board.

    Based on that information it's more tempting to go without until IE6 is dead and buried.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •