473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

form.submit()

5
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.

Expand|Select|Wrap|Line Numbers
  1. function getDestination()
  2. {
  3.     var dest = $('destination');
  4.     var form = $('hotel_search');
  5.     var destUrl = 'getDestination.php';
  6.     var params = 'destinationName=' + $('destinationName').value;
  7.  
  8.     var ajax = new Ajax.Request
  9.     (
  10.         destUrl,
  11.         {
  12.             method: 'post',
  13.             postBody: params,
  14.             onSuccess:
  15.                 function(transport)
  16.                 {
  17.                     var response = transport.responseText || '';
  18.                     dest.value = response;
  19.                     form.submit();
  20.                 },
  21.             onFailure:
  22.                 function()
  23.                 {
  24.                     alert('Something went wrong...');
  25.                 }
  26.         }
  27.     );
  28. }
Jan 21 '08 #1
7 1742
acoder
16,027 Expert Mod 8TB
Show the relevant part of your form.
Jan 22 '08 #2
Nalum
5
Here is a stripped down version of the form

[HTML]
<form id="hotel_search" name="hotel_search" action="searchresults.php" method="post" onsubmit="return validateSearch();">
<input type="hidden" id="destination" name="destination" value="" />
<input type="text" id="destinationName" name="destinationName" value="" />
<input type="button" onclick="getDestination();" id="submit" name="submit" value="Search">
</form>
[/HTML]
Jan 22 '08 #3
acoder
16,027 Expert Mod 8TB
Does the destination value get set as expected?

Are there any errors?
Jan 22 '08 #4
Nalum
5
Hi, the destination value does get set. it all works fine except the form.submit(); part of the javascript.
Jan 22 '08 #5
acoder
16,027 Expert Mod 8TB
Hmm.. everything seems fine.

Is it possible for you to post a link to a page where I can see the problem?
Jan 22 '08 #6
Nalum
5
unfortunately no I don't have a host.
I've put in alerts to the script

Expand|Select|Wrap|Line Numbers
  1. var response = transport.responseText || '';
  2. alert("We have a response");
  3. dest.value = response;
  4. alert("destination has it's value"); // It seems to stop here
  5. form.submit();
  6. alert("Form should now have submitted");
  7.  
I'm gonna try doing this

Expand|Select|Wrap|Line Numbers
  1. var response = transport.responseText || '';
  2. alert("We have a response");
  3. dest.value = response;
  4. alert("destination has it's value");
  5. $('hotel_search').submit();
  6. alert("Form should now have submitted");
  7.  
Edit: No that didn't work either
Jan 23 '08 #7
acoder
16,027 Expert Mod 8TB
If you haven't got a link to show, attach the files here.
Jan 23 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p...
2
by: Matt | last post by:
Can form.submit() submit another form? In the following example, in page1.asp, it is fine to submit the current form: form1.submit(), and and I could see the value "Joe" in page2.asp. However, if I...
2
by: Terence Parker | last post by:
How does one go about submitting a form with a link - but submitting it to a new window AND to a page different to that described within the action="" option of the <form> tag? Say, for example,...
4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
6
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.