0

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

2
  • Basic string concatenation.... Commented Jun 30, 2014 at 18:05
  • 2
    api.jquery.com/jquery.param Commented Jun 30, 2014 at 18:05

2 Answers 2

2

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

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

Hope it helps!

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

1 Comment

If this or any other answers helped you here, feel free to pick an "accepted" answer by clicking a check mark next to it.
2

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>

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.