Results 1 to 6 of 6

Thread: help with submitting data using a form

  1. #1
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default help with submitting data using a form

    I am trying to make a form that submits a value as soon as the option is clicked on.
    i.e without a submit button.

    Is this possible using just HTML?

    after searching google I found I can do this using javascript but there must be a simpler way to do it?

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Is this possible using just HTML?
    No.
    after searching google I found I can do this using javascript but there must be a simpler way to do it?
    No.

    With JavaScript, you could just add this to the <option> tag.
    Code:
    onclick="this.form.submit()"
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    Thanks, any ideas how i'd write this function using javascript?
    I'm know html and php but don't really have alot of knowledge concerning javascript.

    also I take it this will affect users that have javascript disabled.

    Is there an alternative maybe using php instead?

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    PHP is server side, so there'd have to be some sort of javascript to connect to the server in order to submit the form this way. Either way, javascript is the way to go for this. You could do something like this for people who have javascript disabled, however:

    Code:
    <noscript>
    <input type="submit" value="Submit!" />
    </noscript>
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    I've now used javascript

    here's the code I used:

    HTML Code:
    <script type="text/javascript" language="JavaScript">
    function nav()
       {
       var w = document.sortby.price.selectedIndex;
       var url_add = document.sortby.price.options[w].value;
       window.location.href = url_add;
       }
    </script>
    Then called the function like this:
    HTML Code:
    <form name="sortby" method="get">
        <select name="price" onchange="nav()">
            <option value="products.php?sort=ASC">Price (ASC)</option>
            <option value="products.php?sort=DESC">Price (DESC)</option>
        </select>
    </form>

  6. #6
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    good.

    I'd also use the code I gave you for the noscript - for people that don't support javascript.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

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
  •