-1

-Edited-

Hello,

I have a page which contains two forms,I would like to send only the second form using post method.

The form has a valid function which checks valid date, email , etc.

I would like to send the second form without leaving the page , only to send the second form.As far as I know it is doable with AJAX but I'm not sure how to execute it.

Here is an example of the code

Client Side

<body>
<div> ....

<form id='f1'>....</form>
<script> //validation functions, at the end of the main validation function there is a            //code that submits the second form , the one i intend to send.
</script>
<form id='f2'  action='http://mysite/goToMyHandler.cs...>
...some input controls...
<input type='button' value='send' onclick='executeValidation();'>
</form>
</body>

Server Side

myHandler.cs:

...saves data from

Response.Write('Form has been successfully sent');

Thanks

David Rasuli
  • 812
  • 4
  • 15
  • 30
  • what do you mean by *"to post a part of a page"*? – Joseph Mar 22 '12 at 07:38
  • nested `
    `s? http://stackoverflow.com/questions/597596/how-do-you-overcome-the-html-form-nesting-limitation
    – Aram Kocharyan Mar 22 '12 at 07:39
  • I don't want the whole page to be sent , I want to stay at the same page and let only 'myform' be sent to the action adress of the second form. – David Rasuli Mar 22 '12 at 07:40
  • what javascript library are you using – kishu27 Mar 22 '12 at 08:00
  • Your question is still not very clear. Do you intend to send the contents of the `form` tag, or the values of the tags *inside* `form`? It may be best to add an example of the data that you wish to transmit to the question. Maybe even a signature, or simplified pseudocode of the server-side logic to help us understand. – exhuma Mar 22 '12 at 08:05
  • This kind of problems are very often here on StackOverflow and you people need to learn to "guess" a context. For example, OP is learning client-side programming but he may not know it's called that way. But he tries to explain with his own words so that means you need to use your imagination and imagine a context for the described behavior of form elements. Not sure if this makes sense. – Silviu-Marian Mar 22 '12 at 08:15
  • Hey , thanks all for your comments, as Grigore mentioned, I still have to learn how to express myself better, made an entire new edit. Hope it will help solving it – David Rasuli Mar 22 '12 at 08:34

1 Answers1

1

Use jQuery and serializeObject.

This is how you would do it:

$.post($('#myform').attr('action'),$('#myform').serializeObject(),function(r){alert('successfully did it');});
Silviu-Marian
  • 10,565
  • 6
  • 50
  • 72