javascript submit problem : form won't submit

Discussion in 'Javascript' started by Joop, Mar 2, 2005.

  1. Joop

    Joop Guest

    Hi all,

    I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-)

    So, here's my problem :

    I've created a table in my document, presenting a list of items, one
    can 'select' by clicking on it... (Kinda like a menu, you make your
    choice from) But since this table can get very long, I've put
    something of a 'search-form' on top, which enables the user to make a
    selection of products from the list.

    Now, the form uses a "post" method, and submits to itself, using the
    form action. Some PHP script will make sure that the form is filled
    out already, the next time it's presented.

    The table, containing a list of products is presented, below the form.
    When a user clicks on a product, the product should be "selected". At
    first i just used a <a href="zoeken.php?prod_id=24"> link to do this,
    but the problem is that my form won't remain in tact.

    So now, the global idea is to submit the form after setting a hidden
    form-field using JavaScript, using a onClick event.

    Here's my code :

    <-- the script -->

    <head>
    <script language="JavaScript">
    <!--
    var old_Color;

    function select_this(id)
    {
    old_Color = document.getElementById(id).style.backgroundColor;
    document.getElementById(id).style.backgroundColor = '#FFCCCC';
    }

    function deselect_this(id)
    {
    document.getElementById(id).style.backgroundColor = old_Color;
    }

    function submit_this(id)
    {
    document.forms['zoeken'].select_id.value = id;
    document.forms['zoeken'].submit();
    }
    -->
    </script>
    </head>

    <body>

    <-- the form -->

    <form name="zoeken" action="zoeken.php" method="post" style="margin:
    5px;">

    <-- a very long form with a lot of variable goes here -->

    <input type="submit" value="Zoeken" class="formulierknop">
    <input type="hidden" name="select_id" value="">

    </form>


    <-- the tablerows, in the table, all look like this -->

    <tr id="1" onClick="submit_this(1);" onMouseOver="select_this(1);"
    onMouseOut="deselect_this(1);" style="cursor: hand; background-color :
    'transparent';">

    </tr>


    Cool huh?!? Everything seems to work, but the submit function. Did I
    do something terribly wrong?!? I probably did... :-(

    WHY WON'T MY FORM SUBMIT WHEN I CLICK ON A TABLE-ROW?!?!?!?!? :-S

    Thnx in advance to everyone spending time on this! ;-)
    Joop, Mar 2, 2005
    #1
    1. Advertising

  2. Joop

    hippo Guest

    Hi Joop,

    I put your code in a html file (ie6.0) and it works...?

    But what you can try to include your table (with the code rows)
    between the <form></from> tags.

    Maybe this works?

    Hippo from [NL]
    --
    remove xxx from mail
    hippo, Mar 2, 2005
    #2
    1. Advertising

  3. Joop

    hippo Guest

    Sorry, but it also work in a php file.

    No offense, but are you using table cells in your table rows?

    Like:

    <tr id="1" onClick="submit_this(1);" onMouseOver="select_this(1);"
    onMouseOut="deselect_this(1);" style="cursor: hand; background-color :
    'transparent';">

    <td>blablabla</td>

    </tr>

    otherwise it is very difficult to determine where to click:)

    Please response your results

    Greetz,
    Hippo from [NL]
    --
    remove xxx from mail
    hippo, Mar 2, 2005
    #3
  4. Joop

    hippo Guest

    You could submit your form by javascript:


    document.YOURFORMNAME.submit();


    >Ok,
    >
    >thanks for reply-ing this quickly!!!
    >
    >Perhaps I should have mentioned that my code is placed in an <iframe>
    >named "content". I don't really know if that makes a difference.
    >
    >I have a file called "index.php" with the <iframe name="content"
    >src="zoeken.php"></iframe>, and then I have a file called "zoeken.php"
    >with the code in it as mentioned above!
    >
    >And yes, I did put some <td></td> cells in there as well, but they're
    >"code-less", so I felt no need to bother any reader with that! ;-)
    >
    >The code does change the variable "select_id", so when I manually submit
    >the form, using the submit button, after clicking on one of the <tr>'s,
    >the clicked <tr> is selected. But I want my form to submit in the
    >onClick event! :)
    >
    >Anybody?!?
    >
    >*** Sent via Developersdex http://www.developersdex.com ***
    >Don't just participate in USENET...get rewarded for it!
    hippo, Mar 2, 2005
    #4
  5. Joop

    Joop Guest

    Nope... Won't work either... Sorry... :-(

    Anybody?!? I'm stuck at this for over a week now, and don't have the
    foggiest idea to what's wrong...



    > You could submit your form by javascript:
    >
    >
    > document.YOURFORMNAME.submit();
    >
    >
    > >Ok,
    > >
    > >thanks for reply-ing this quickly!!!
    > >
    > >Perhaps I should have mentioned that my code is placed in an <iframe>
    > >named "content". I don't really know if that makes a difference.
    > >
    > >I have a file called "index.php" with the <iframe name="content"
    > >src="zoeken.php"></iframe>, and then I have a file called "zoeken.php"
    > >with the code in it as mentioned above!
    > >
    > >And yes, I did put some <td></td> cells in there as well, but they're
    > >"code-less", so I felt no need to bother any reader with that! ;-)
    > >
    > >The code does change the variable "select_id", so when I manually submit
    > >the form, using the submit button, after clicking on one of the <tr>'s,
    > >the clicked <tr> is selected. But I want my form to submit in the
    > >onClick event! :)
    > >
    > >Anybody?!?
    > >
    > >*** Sent via Developersdex http://www.developersdex.com ***
    > >Don't just participate in USENET...get rewarded for it!
    Joop, Mar 18, 2005
    #5
  6. Joop

    Guest

    I have had this problem for several years an only just figured out how
    to deal with it. There day I got this idea to check all of the
    attributes of the from I was calling submit() on from a javascript
    function. Low and behold.. Many of the attributes were blank. I've
    had forms[].method, forms[].enctype, forms[].action all be empty and so
    when you call forms[].submit(), nothing happens. I don't understand
    why this happens either because those values are set in my <form> tag,
    and somehow get lost. So my fix is to set them in the javascript
    function if they are empyt.

    For instance:

    if( document.forms[index].action == "" )
    document.forms[index].action = "multipart/form-data";
    document.forms[index].submit();

    It works so long as the action, method, and enctype are set.
    It's also possible that some of the data you want in your <input> tags
    isn't set as you expected. Check those as well if you have further
    problems.

    -Dieter
    , Mar 23, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    4
    Views:
    8,312
  2. Replies:
    2
    Views:
    6,170
  3. SuperMetroid

    Form Value Won't Post/Submit

    SuperMetroid, Oct 12, 2009, in forum: Python
    Replies:
    4
    Views:
    1,181
    SuperMetroid
    Oct 13, 2009
  4. Andy Fish

    how to make a form that won't submit

    Andy Fish, Aug 28, 2003, in forum: Javascript
    Replies:
    2
    Views:
    121
  5. Replies:
    3
    Views:
    654
Loading...

Share This Page