Results 1 to 4 of 4

Thread: Submitting Parameters to a JavaScript Function

  1. #1
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Submitting Parameters to a JavaScript Function

    I have a form on my site which when submitted, sends the result to a javascript function, which then properly handles the data. This allows the form to be submitted through javascript without the user leaving the page. My problem is that whether I use the "get" or "post" method, I can't figure out how to submit the data properly.

    Here's an example of how this should work:

    If the user selects "Selection 2" from the dropdown and clicks submit, then the action should be "javascript:submittopage('submitform.php?Option=2', '1');""

    What I can't figure out is how to append the "?Option=2" to the end of the submitform.php URL. I've been trying to figure this out for quite some time, but I'm stumped. Is there anyone here who's more proficient in javascript and who knows how to make this work?

    Thanks!

    Here's my form code:
    Code:
    <form id="form1" name="form1" method="get" action="javascript:submittopage('submitform.php', '1');">
      <label>
      <select name="Option">
        <option value="" selected="selected">Select An Option</option>
        <option value="1">Selection 1</option>
        <option value="2">Selection 2</option>
        <option value="3">Selection 3</option>
        <option value="4">Selection 4</option>
        <option value="5">Selection 5</option>
      </select>
      </label>
      <label>
      <input type="submit" name="Submit" value="Submit">
      </label>
    </form>

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by WebmasterGeeks
    I have a form on my site which when submitted, sends the result to a javascript function, which then properly handles the data.
    What does "properly handle" mean?

    This allows the form to be submitted through javascript without the user leaving the page.
    And makes the form useless without scripting support.

    There is little point in trying to fight how the Web works, particularly when it means reinventing the wheel square. Perhaps if you explain the real issue you're trying to solve, you can get a better suggestion.

    Mike

  3. #3
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Thanks Mike,

    By "Properly handles" I mean that it processes the data. If you look at the example code I provided, you'll see that the script pulls submitform.php, which would clearly indicate scripting support. But that really makes no difference in terms of the question that I'm asking.


    What I'm doing is simple...

    1) The user selects an item from the dropdown menu, and clicks submit.
    2) The selected item is sent to a script.
    3) The script tells the visitor "thanks" and uploads the data to the server.

    Steps #1 and #3 are finished - they work great. The only thing I'm stuck on is how to let the script know which item has been selected.

    So... the form currently looks like this:
    Code:
    <form id="form1" name="form1" method="get" action="javascript:submittopage('submitform.php', '1');">

    and I essentially need it to look like this:

    Code:
    <form id="form1" name="form1" method="get" action="javascript:submittopage('javascript:submittopage('submitform.php?option=(which ever form item was selected)', '1'); ">
    It would be easy for me to assign the value for "option" if I were using php, but this needs to be client side, and automatically update the form when either the dropdown item is selected or the form is submitted.

    Thanks for all your help.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you look at the example code I provided, you'll see that the script pulls submitform.php, which would clearly indicate scripting support.
    But it's still useless if the client doesn't have scripting support.
    and I essentially need it to look like this:
    No, you don't. You need a fallback. Probably something like this:
    Code:
    <form id="form1" name="form1" method="get" action="submitform.php" onsubmit="submittopage('submitform.php', '1'); return false;">
    submittopage(), of course, will process the form into some form of AJAX data that will include the contents of all the form elements.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •