form.submit()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nalum
    New Member
    • Jan 2008
    • 5

    form.submit()

    Hello all,
    I've had a look around but couldn't find an answer to my question.
    I'm trying to submit a form using the javascript .submit() function but it doesn't seem to want to work. I'm using Ajax to get a value from a database and put it into a hidden field called destination and then want to submit the form.

    Here is my code. The function is called by a button input.

    [CODE=javascript]function getDestination( )
    {
    var dest = $('destination' );
    var form = $('hotel_search ');
    var destUrl = 'getDestination .php';
    var params = 'destinationNam e=' + $('destinationN ame').value;

    var ajax = new Ajax.Request
    (
    destUrl,
    {
    method: 'post',
    postBody: params,
    onSuccess:
    function(transp ort)
    {
    var response = transport.respo nseText || '';
    dest.value = response;
    form.submit();
    },
    onFailure:
    function()
    {
    alert('Somethin g went wrong...');
    }
    }
    );
    }[/CODE]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Show the relevant part of your form.

    Comment

    • Nalum
      New Member
      • Jan 2008
      • 5

      #3
      Here is a stripped down version of the form

      [HTML]
      <form id="hotel_searc h" name="hotel_sea rch" action="searchr esults.php" method="post" onsubmit="retur n validateSearch( );">
      <input type="hidden" id="destination " name="destinati on" value="" />
      <input type="text" id="destination Name" name="destinati onName" value="" />
      <input type="button" onclick="getDes tination();" id="submit" name="submit" value="Search">
      </form>
      [/HTML]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Does the destination value get set as expected?

        Are there any errors?

        Comment

        • Nalum
          New Member
          • Jan 2008
          • 5

          #5
          Hi, the destination value does get set. it all works fine except the form.submit(); part of the javascript.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Hmm.. everything seems fine.

            Is it possible for you to post a link to a page where I can see the problem?

            Comment

            • Nalum
              New Member
              • Jan 2008
              • 5

              #7
              unfortunately no I don't have a host.
              I've put in alerts to the script

              [code=javascript]
              var response = transport.respo nseText || '';
              alert("We have a response");
              dest.value = response;
              alert("destinat ion has it's value"); // It seems to stop here
              form.submit();
              alert("Form should now have submitted");
              [/code]

              I'm gonna try doing this

              [code=javascript]
              var response = transport.respo nseText || '';
              alert("We have a response");
              dest.value = response;
              alert("destinat ion has it's value");
              $('hotel_search ').submit();
              alert("Form should now have submitted");
              [/code]

              Edit: No that didn't work either

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                If you haven't got a link to show, attach the files here.

                Comment

                Working...