Hi All,

I have the following situation.  I want to use jquery to send form data to a server to save the data to a db, and then use jquery to read the server response to update some hidden id's.

The basic html I have is

<div class="input">
   <form action="" method="post">
      <input id="record_id" value="0" />
      <other form data>
   </form>
</div>

Initially the record_id is set to 0 in the form for a new record.  Now I want to save the record with jquery with code that looks like

prepare_fill_submit = function(){
   var record_id        =$("input#record_id",this).val();
   /*Get other form data*/
   $.post("/save_record",{
      'record[id]' : record_id
   }, fuction (html) {
      var new_record_id = $("input#record_id",html).val();
      /* alert(html); */
      /*Code that would put this new record_id into the existing form*/
   });

   return false;
}

(with appropriate code to make sure that the jquery function is called when the form button is clicked.  something like

$("div.input form").submit(prepare_fill_submit);

)

The post is working meaning that if I uncomment the alert(html); line in the post function, I see the html form (as returned by the /save_record url) now populated with a brand new record_id which is not 0.  However, the existing html form still has the record_id as 0, meaning that the line

var new_record_id = $("input#record_id",html).val();

seems to be accessing the current DOM, and not the returned html.  Any hints as to why this may be the case?

Thanks for your help,

Julius

--
-----------------------------------------------------
http://openwetware.org/wiki/User:Lucks
-----------------------------------------------------
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to