Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Simple form Q

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Auckland New Zealand
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple form Q

    This is the code for the form..


    <form>
    <select
    onChange="if(this.selectedIndex!=0)
    self.location=this.options[this.selectedIndex].value">
    <script language="javascript" src="../tech/drop7.js"></script></form>

    This is the "drop7.js"

    document.write('<option value="" selected>Select a Region<option value="national.html">National<option value="franklinh.html">Franklin<option value="ham1.html">Hamilton<option value="northh.html">NorthHarbour<option value="otara.html">Otara<option value="papat.html">Papatoetoe<option value="tga_h.html">Tauranga</select>');

    When I test through Doctor html I get ..

    "select tag needs a closing tag"

    and...

    "Form does not have an action defined"


    The form seems to work well on all browsers so far.

    If I was to add the </select> where would it go?

    What would the "action" be?

    Thanks in advance

    Tonz
    Beware, the Cybertooth tiger cometh

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Maine, USA
    Posts
    573
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Tonz,

    Try this code, it's essentially the same as yours with a few minor modifications. Some validators will be thrown when you use document.write. I validated it through HTML Tidy and there were only a few things it picked-up on (can't remember them all now as I sort of did this in a hurry...lol). The code seems to work fine when I tested it as well:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
    <head>
    <title>Testing...</title>
    </head>
    <body>
    <form name="myForm" action="#">
    <select onchange="if(this.selectedIndex!=0) self.location=this.options[this.selectedIndex].value">
    <script language="javascript" type="text/javascript">
    document.write('<option value="" selected>Select a Region<option value="national.html">National<option value="franklinh.html">Franklin<option value="ham1.html">Hamilton<option value="northh.html">NorthHarbour<option value="otara.html">Otara<option value="papat.html">Papatoetoe<option value="tga_h.html">Tauranga');
    </script>
    </select>
    </form>
    </body>
    </html>
    Any better or did I mess it up more by being hasty ?
    boxer_1
    CodingForums Moderator
    "How did a fool and his money get together in the first place?"

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    Maine, USA
    Posts
    573
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just to give you another option, here's another version (a little different) you could try out:

    Code:
    <html>
    <head>
    <title>Testing...</title>	
    <script language="JavaScript" type="text/javascript">
    destination = new Array ("","national.html","franklinh.html","ham1.html","northh.html","otara.html","papat.html","tga_h.html");
    function region(pick){
    if (pick != 0)			
    location.href = destination[pick];	
    }	
    </script>
    </head>
    <body>	
    <form>		
    <select onChange="region(this.selectedIndex);">			
    <option>Select a Region</option>			
    <option>National</option>			
    <option>Franklin</option>			
    <option>Hamilton</option>		
    <option>NorthHarbour</option>
    <option>Otara</option>
    <option>Papatoetoe</option>
    <option>Tauranga</option>
    </select>	
    </form>
    </body>
    </html>
    Accomplishes essentially the same purpose, perhaps a little easier to work with .
    boxer_1
    CodingForums Moderator
    "How did a fool and his money get together in the first place?"

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is always better to close a tag. You should close the tag. Many times even if you don't close a tag, your page may render correctly but not on all browsers. As far as the form action, it is only required if you need server-side processing of the form. You can leave it as action=""

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Auckland New Zealand
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Boxer.

    Many thanks, looks great.


    I want to keep the external script is so that when a new region is added, I don't have to go through every page that has the form on, and update it. (obviously), so I think your first mod, will do the job just great.

    Having the </select> on the other side of the .js was one I should have guessed.

    Thanks agin

    Tonz

    Beware, the Cybertooth tiger cometh


  •  

    Posting Permissions

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