Results 1 to 6 of 6

Thread: Help Validating XHTML this Javascript Form

  1. #1
    Join Date
    Feb 2006
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Validating XHTML this Javascript Form

    I got this Javascript form for a combo box, it works fine but I like to have my stuff validate for XHTML 1.0 strict

    Here is the link to the script

    http://javascriptkit.com/script/cut185.shtml

    Works great, as usual I stuck a link to the javacript into the webpage so I didn't have to worry about most of the javascript so I was left with this

    <form name="jumpy">
    <p><select name="example" size="1" onChange="gone()">
    <option value="http://www.cnet.com">Cnet</option>
    <option value="http://www.cnn.com">CNN</option>
    <option value="http://www.geocities.com">Geocities</option>
    </select>

    <input type="button" name="test" value="Go!"
    onClick="gone()">
    </p>
    </form>

    I know you have to us lowercase for the XHTML to validate, how would you arrange this to validate? The name tag is depreciated but I was told to use ID but I'm not using this right cause it doesn't work

    I'd appreciate any help

    THanks

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,314
    Thanks
    1
    Thanked 241 Times in 236 Posts

    Default

    Hi there Markxxx,

    try it like this...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <script type="text/javascript">
    //<![CDATA[
       var df;
    window.onload=function() {
       df=document.forms[0];
    df[0].onchange=function(){
       gone(this.value);
     }
    df[1].onclick=function(){
       gone(df[0].options[df[0].selectedIndex].value);
      }
     }
    function gone(url){
       location.href=url;
     }
    //]]>
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <select>
     <option value="http://www.cnet.com">Cnet</option>
     <option value="http://www.cnn.com">CNN</option>
     <option value="http://www.geocities.com">Geocities</option>
    </select>
     <input type="button" value="Go!"/>
    </div>
    </form>
    
    </body>
    </html>
    
    
    coothead

  3. #3
    Join Date
    Feb 2006
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks the script does work and validates fine, one question, I only want the onclick, I don't want the onchange.

    I have my javascript book here, but no matter what I do, even when I remove the whole thing it keeps going to the site as soon as I touch the drop down box.

    LOL

    It shouldn't be this hard but I am not getting something. Thanks for the help

    mark

  4. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,314
    Thanks
    1
    Thanked 241 Times in 236 Posts

    Default

    Hi there Markxxx,

    I did not know whether you required the onchange or the onclick handler, so I allowed for both options in the coding.
    Simply remove the highlighted snippet from the script...
    Code:
    
    <script type="text/javascript">
    //<![CDATA[
       var df;
    window.onload=function() {
       df=document.forms[0];
    df[0].onchange=function(){
       gone(this.value);
     }
    df[1].onclick=function(){
       gone(df[0].options[df[0].selectedIndex].value);
      }
     }
    function gone(url){
       location.href=url;
     }
    //]]>
    </script>
    
    ...to remove the onchange handler.

    coothead

  5. #5
    Join Date
    Feb 2006
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you I swear I did that before and it didn't work...LOL

    Maybe the page was cached or something. Oh well it works great now.

    Thanks for helping me I appreciate it

  6. #6
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,314
    Thanks
    1
    Thanked 241 Times in 236 Posts

    Default

    No problem, you're welcome.

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
  •