Avien Avien -4 years ago 81
HTML Question

jQuery passing values from one form to preivous form

Is it possible to find out what form you're currently on from a js file?

This is my issue.. I have a form, form1, that includes a table.. when a row in the table is clicked on another form pops up, form2. If the user "saves successfully" on form2, the form closes and form1 comes back into focus..my question, is it possible to send an id or call a function when that form closes to set/change values

what I want to do is change the row attribute of the row the user saved on form1.

table.row[1].color = red

after save

table.row[1].color = green

how do i access/set values of the table on form1.. I would assume I need to do something like this once I know what form I'm on..this is all being done in a js file..

foreach(row in table)
if (FormName.GeneralReport.rows[i]).attr("userid") == 'id')
$(FormName.GeneralReport.rows[i]).attr("isValid", "True");
$(formNameGeneralReport.rows[i]).css("background-color:", "green");

or... can I add a function to form1 and call that function from my js file?

Answer Source

It's hard to give an detailed answer because the whole construct is described a bit vague. Assuming that this all happens entirely at the client side and thus no new HTTP requests are been sent to the server side, generally you can just "pass" values through by setting some (invisible) DOM element and/or attribute with that value. Add for example an <input type="hidden" name="formid"> to the form in the dialog and add something like this to the edit button:

$('.edit').click(function() {
    var formid = $(this).parents('form').attr('id');
    $('#dialog input[name=formid]').val(formid);
    // ...

..and add something like this to the save button of the dialog:

$('#dialog .save').click(function() {
    var formid = $(this).parents('#dialog').find('input[name=formid]').val();
    var form = $('#' + formId);
    // ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download