SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2006
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with passing variable to popup

    Hello,

    I've perused the posts on popups and variable and can't seem to get what I need. Can someone take a look at my code and tell me what I'm missing.

    I want to open a popup window and provide a variable that I grab from a select list on the main page using javascript. This code works to grab the selected option in the list and open a new page but I want it to do this in a pop up so I can still see the main page.

    HTML Code:
    <SCRIPT language="JavaScript">
    function reload(form)
    {
    var val=form.county.options[form.county.options.selectedIndex].value;
    self.location='/dataservices/countyinfo.php?pjid=<?php echo $Project_ID;?>&sid=<?php echo $Site_ID;?>&county=' + val ;
    }
    </script>
    PHP Code:
    <?php
    // Get records in all columns from countydistrict_tbl.
    $countyresults=mysql_query("SELECT * FROM countydistrict_tbl WHERE Project_ID=$Project_ID ORDER BY county");

    $options = array(); 
    while (
    $countyrow mysql_fetch_assoc($countyresults)) { 
        
    $options[$countyrow['county']] = $countyrow['county']; 

    $list ''
      foreach (
    $options as $value => $text) { 
                        
    $list .= "  <option value=\"$value\"$is_selected>$text</option>\n";
    }
    echo 
    "<select name='county' id='county' ondblclick='reload(this.form)' size='5'>\n$list</select>\n"
    }
     
    ?>
    This is my attempt at making it as a popup window. What am I missing? I can't seem to get the javascript variable VAL to pass into the URL. Be nice I'm new to javascript and all. Thanks in advance this forum has been a big help already.

    HTML Code:
    <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
    <!--
    var val=form.county.options[form.county.options.selectedIndex].value;
    
    function selectWindow()
       {
    	 var address
    	 address = "/dataservices/countyinfo.php?pjid=<?php echo $Project_ID;?>&id=<?php echo $Site_ID;?>&county=" + val
    	 window.open(address,"",'status=yes,resizable=yes,scrollbars=yes,location=yes');
       }
    
    }
    PHP Code:
    <?php
    // Get records in all columns from countydistrict_tbl.
    $countyresults=mysql_query("SELECT * FROM countydistrict_tbl WHERE Project_ID=$Project_ID ORDER BY county");

    $options = array(); 
    while (
    $countyrow mysql_fetch_assoc($countyresults)) { 
        
    $options[$countyrow['county']] = $countyrow['county']; 

    $list ''
      foreach (
    $options as $value => $text) { 
                        
    $list .= "  <option value=\"$value\"$is_selected>$text</option>\n";
    }
     
    ?>
    <select name="county" id="county" ondblclick="selectWindow()" size="5"><?php echo $list?> </select>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Once the popup opens, you should be able to see the URL used in the page properties, to verify if your county is being passed.

    I noticed that you are declaring the val variable outside of your function - could it be that the variable is being set on page load instead of when the user does something? Maybe you need to put that var val=... line inside your popup function.


Bookmarks

Posting Permissions

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