1

Here if first_aid checkbox is selected,a button called Add treatment notes will appear and by clicking Add treatment notes the tab gets open which contain treatment notes and description.For saving purpose a save button is avail inside the tab and it is saving the values also.

But my problem is,if i choose first_aid check box and click next button in main page,it should save the checked one in database.Previously,save was happening if i open the Add treatment notes tab and click save.

I want to know how to connect the same save function to two buttons,namely save button in Add treatment notes tab already have save function,so how to connect that same to the next button in main page.Tab is in the main page,it is normally hidden,will open if any check box is selecetd

user2086641
  • 4,331
  • 13
  • 56
  • 96

2 Answers2

1

If I got your question correctly, you want to do the same thing on two different button clicks.

You can add onclick events to both buttons and call the same js function. And then submit the related form inside that function.

Sudipta
  • 4,773
  • 2
  • 27
  • 42
  • 500 error means Internal server error; i.e some unhandled error in your python code. What python error are you getting? – Sudipta Jul 03 '13 at 14:51
  • I used the onclick in the next button,if the tab is in open condition it is saving the checked one ,If the Add treatment notes tab is in hiden condition the check box is not saving.Need help – user2086641 Jul 03 '13 at 16:39
  • In your js function(which is being called onclick), submit the form. `document.getElementById("formId").submit();` – Sudipta Jul 04 '13 at 10:53
  • @user2086641 I would appreciate if you put in some research before asking/commenting here. Getting elements by class name is very simple. http://stackoverflow.com/questions/3808808/how-to-get-element-by-class-in-javascript. This question discusses at length about the topic. But do you want all 3 forms to be submitted? If not, then you have to add id attribute to your forms. – Sudipta Jul 04 '13 at 15:06
0

If I understood your question is right... You must use JavaScript. You can save the intermediate data at the JavaScript's object or use cookie for it. Both cases should uses only by client's side. You should remember {% csrf_token %} would be different for each form.

For to saving cookie you can use it plugin. Example usage:

// 7 day
jQuery.cookie('name_cookie', 'value_cookie', { expires: 7 });
Abbasov Alexander
  • 1,848
  • 1
  • 18
  • 27
  • You should choose decision that would be simplest for you. I suggest to save values at the cookie or JavaScript object and before sending form saved data must be serialized. – Abbasov Alexander Jul 03 '13 at 18:12