views:

47

answers:

2

I'm trying to do a simple update, but can't figure out somthing. I have a table that i get from a DB with an Edit button that when i press change to a Save button so i can save with Ajax the record that the user just edit. I'm doing the first part just fine, have one function that do all the jquery stuff on the page (that is working just fine).

Now I want to change the $('#a'+productID) line to save insted of edit. i am changing the link attribute also, so when the user presses save it will send him to a function that will make the Ajax request and update the record.

But i dont have a clue how to start that....I don't think it has any thing to do with any bind function becouse i am allready binded by calling the save function (or am i wrong and need to bind antway???) can any one help me out here?

P.S. the save function recives the productID do i have the right product when i will need it.

Don't have a code to send for the save function becouse i don't know how to start it and every thing i tried doesn't work....sorry :-(

A: 

It might be easier if you simply had both buttons on the page and toggled between them depending on the page state.

 <a id="editButton" href="http://example.com/widget/edit/1"&gt;Edit&lt;/a&gt;
 <a id="saveButton" href="http://example.com/widget/update/1" style="display: none;">Save</a>

 $(function(){
      $('#editButton').click( function() {
          // set up the form as edit...
          $(this).hide();
          $('#saveButton').show();
          return false;
      });
      $('#saveButton').click( function() {
         var button = $(this);
         var href = button.attr('href');
         $.post(href,$('form').serialize(), function() {
               // change form back to readonly...
               button.hide();
               $('#editButton').show();
         }
      });
 });
tvanfosson
10x, found the solution....:-)
Erez
A: 

I guess that my biggest questian is how do i start writing the code when i am getting a parameter to a JS function that suppose to do AJAX request....i can't see there any bind or any thing...that is my problem (becouse the click was allready made to triger the function so i can't bind a 'click' again). if i get started i will be able to do the rest myself (i hope)....:-)

10x any way :-)

Erez