1

This is my first code with jQuery, so be indulgent please. The code below is part of a table in which each row displays: a reload button (Reload.gif), and two comboboxes (cmb1 and cmb2). Here is the edited code for just one row:

<table>
<form name="myformname" form action="Handler.php" method="post">
   <tr>
      <td>
          <input type="hidden" name="MyQuestion" value="0">
          <input type="image" src="Reload.gif" border="0"/>
      </td>
      <td>
          <select name="cmb1"><option>One</option><option>Two</option></select>
      </td>
      <td>
          <select name="cmb2"><option>A1</option><option>A2</option></select>
      </td>
   </tr>
</form>
</table>

Variables MyQuestion, cmb1 and cmb2 (user-selected) are passed to Handler.php (as all are in the same form), that search data in databases and reload the page with the new data. This is working OK.

But now I want to change the logic, cause I dont want to reload the whole page, but only the row that was clicked. I tried with jQuery something like this (OnClick added to Reload.gif!):

<table>
   <tr>
      <td>
          <input type="hidden" name="MyQuestion" value="0">
          <input type="image" onclick="recp('0')" src="Reload.gif" border="0" name="MyQuestion" value="0"/>
      </td>
      <td>
          <select name="cmb1"><option>One</option><option>Two</option></select>
      </td>
      <td>
          <select name="cmb2"><option>A1</option><option>A2</option></select>
      </td>
   </tr>
</table>

And in the header I added this code (I took it from here)

function recp(id) {
  $('#myStyle').load('data.php?id=' + id);
}

I got some results for the id, but here is my question: In the

load('data.php?id=' + id)

, can I send multiple variables (id, cmb1 and cmb2)?

2
  • 3
    load('data.php?id=' + id + '&cmb1=' + cmb1 + '&cmb2=' + cmb2) Commented Aug 15, 2014 at 21:28
  • You can also send an object: api.jquery.com/load/#example-3 Commented Aug 15, 2014 at 21:29

2 Answers 2

4

To send multiple variables you could use for example,

load('data.php?id=' + id + '&var1=' + var1 + '&var2=' + var2)

For more examples and other ways to do it, have a look in the jQuery manual for the load() function.

Sign up to request clarification or add additional context in comments.

Comments

0

Why not use .serialize()?

$("#myStyle").load('data.php?' + $("form[name=myformname]").serialize());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.