Hello All,
I am having one javascript function which is written in PHP. It's having one javascript variable. Here is the function.

$js = "<script language='javascript'>\n" .
	"function getValue(val)\n" .
	"{\n" .
	"window.location.href='http://localhost/users/page/'+val\n" .
	"}\n" .
	"</script>";

This function is called onchange event of combo, But I am not getting the value of javascript variable val. Is it possible to get the javascript variable's value in PHP? If yes then how? Please help me. Thanks in advance.

    ya thats right but what I want is to do is to redirect the page using javascript variable and the code is in php.

    the modified code is as below.

    $redirect = site_url($path.'/page/+this.value');
    
    $pagingLink .="<select name='pageNo' id='pageNo' style='width:60px' onChange=\"window.location.href='".$redirect."' \">";
    

    I want to get this.value's value. Can I?

      You should use quotes (if needed with backslashes) properly to let JS know where text is and where variable is. Try this:
      $redirect = site_url('\''.$path.'/page/\'+this.value');

        Thanks for the reply....
        I 've tried the way that u 've said but it is not working...
        When the url is created it is considering js variable as +this.value instead of considering its value. I tried with modifying this code but no success yet...😕 what can i do further?

          Look, I cannot see your full code so maybe there is something else. What I can do is to give you 100% working example:

          <?php
          $str = '';
          $str .= '<select onchange="alert(\'JS var parsed by PHP: \'+this.value);">';
             $str .= '<option value="1">1</option>';
             $str .= '<option value="2">2</option>';
          $str .= '</select>';
          echo $str;
          ?>
            Write a Reply...