Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to use a Javascript variable in PHP

    I'm trying to use a JS variable from a chained menu script that I found to populate a variable in a PHP RSS script that I have? Unfortunatley I'm not very expierienced in JS, and am just learning PHP the JS code looks like this:

    function goListGroup(){
    for (i=arguments.length-1;i>=0; i--){
    if (arguments[i].selectedIndex!=-1){
    var selectedOptionvalue=arguments[i].options[arguments[i].selectedIndex].value
    if (selectedOptionvalue!=""){
    if (onclickaction=="alert")
    alert(selectedOptionvalue)
    else if (newwindow==1)
    window.open(selectedOptionvalue)
    else
    window.location=selectedOptionvalue
    break

    The final variable 'selectedOptionvalue' in its original form opened a URL, but what I'm hoping to do is to assing that value to a variable in my config.php file. That line looks like this:

    $keyword = "my very own keyword";

    I know that JS is client side and php is server side, so I'm not sure how to 'merge' the to codes

    Thanks in advance for your help

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    I have the same problem (i think)
    Trying to pass a javascript value to php:
    use ajax
    Passing Javascript var to PHP without redirection

    for using a php value in javascript, just use

    Code:
    ...js codes...
    var phpVar = "<?php echo $myvar ?>";
    Or something like that. you get the point...im not too great with php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •