简体   繁体   中英

pass the parameter in javascript url

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");
      }

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);
      }

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.

您需要像这样连接字符串:

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

更改window.open行,如下所示:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM