Kevin Spurs
Kevin Spurs

Reputation: 39

Javascript Help Passing Data via URL

Hi I wonder if someone could help me with this small issue I have the following code which I need to modify.

<script type="text/javascript">
function code(id) {
  $('#myStyle').load('myphp.php?id=' + id);
}
</script>

I need to pass another variable into this code and add it to the GET part of the URL for example above it will include the URL myphp.php?id=124545

I want to add a second variable called num to the URL part but am confused what the code will need to become to make the correct post via GET

<script type="text/javascript">
function code(id,num) {
  $('#myStyle').load('myphp.php?id=' + id); // how do I add the &num=124 for example
} 
</script>

Thanks in advance

Upvotes: 0

Views: 55

Answers (2)

Noble Mushtak
Noble Mushtak

Reputation: 1784

Concatenate "&num="+num onto the string you already have:

<script type="text/javascript">
function code(id,num) {
  $('#myStyle').load('myphp.php?id=' + id  + "&num=" + num); // how do I add the &num=124 for example
} 
</script>

Upvotes: 2

A Sharma
A Sharma

Reputation: 646

Simple. Use: $('#myStyle').load('myphp.php?id=' + id + '&num=' + num);

Reference: http://www.quirksmode.org/js/strings.html#conc

Hope it helps!

Upvotes: 2

Related Questions