2

I want to pass the parameter value in url.I have the parameter 'redir'.redir value is changed dynamically as 1,2,3,4,5,... or any number I passed the redir value from php.I passed the value to the newpage() function. I want to pass dynamic redir value as in rec_resume_post.php?req_id=1 or rec_resume_post.php?req_id=2.

<?php
 echo '<tr><td>'.$title.'</td><td>'.$c_name.'</td><td>'.$e_first_name.'</td><td>'.$num.'</td><td><input type="submit" value="submit" onClick="newpage('.$req_id.');" /></td></tr>'; 
?>
 <script>
   function newpage(redir){
    window.alert(redir);
    window.open("rec_resume_post.php?req_id=redir");
      }
1
  • 2
    window.open("rec_resume_post.php?req_id=" + redir); Commented Jun 2, 2015 at 8:56

4 Answers 4

2

Try like this:

window.open("rec_resume_post.php?req_id=" + redir);

So it would be like this:

<?php
 echo '<tr><td>'.$title.'</td><td>'.$c_name.'</td><td>'.$e_first_name.'</td><td>'.$num.'</td><td><input type="submit" value="submit" onClick="newpage('.$req_id.');" /></td></tr>'; 
?>
 <script>
   function newpage(redir){
    window.alert(redir);
    window.open("rec_resume_post.php?req_id"+ redir);
      }
Sign up to request clarification or add additional context in comments.

Comments

2

Add the variable to the string.

<?php
 echo '<tr><td>'.$title.'</td><td>'.$c_name.'</td><td>'.$e_first_name.'</td><td>'.$num.'</td><td><input type="submit" value="submit" onClick="newpage('.$req_id.');" /></td></tr>'; 
?>
 <script>
   function newpage(redir){
    window.alert(redir);
    window.open("rec_resume_post.php?req_id"+ redir);
      }

Edited: Suggested the join method for combining strings. But as Rahul pointed out below, using + is the best way to combine strings.

5 Comments

I dont think that .join() is going to be useful here!
Maybe not, but I just want to show another way to combine strings in javascript. I personally don't like all the '+' characters when combining strings in javascript.
I'm curious what you think is the best practise Rahul, I'm sometimes wondering if there is a better way to do this.
Not sure about the best practise but yes as far as the performance is concerned "+" is definetly the fastest. Here is a test demo to justify that: jsperf.com/concat-vs-plus-vs-join
Also what I have seen is that when we are concatenating the url then 99% of the time we use the "+" operator. So my assumption is that its because of the performance issue and hence a recommended practise
1

You need to concat your string like this:

window.open("rec_resume_post.php?req_id="+redir);

Comments

1

Change the window.open line like follows:

window.open("rec_resume_post.php?req_id=" + redir);

Comments

Your Answer

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