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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unable to get Select Tag value (But input class works)

    Hi,

    Can someone be the expert I need and help me see why I can't get this value to pass in PHP?

    I have a PHP page with three DIVs. On page load, only the first DIV (DIV#1) has controls. The first DIV (DIV#1) contains a button that, when clicked, generates a control and button in DIV#2. The intent is to have a user select a value from a list box in DIV#2 and then click an action button also in DIV#2. The resulting action should be for the value selected in the listbox of DIV#2 to be displayed in DIV#3. I am using AjaxCore/Prototype.js for AJAX like effects.

    The listbox is displayed and appears ok, but I cannot get a value from the listbox (Select Tag). When I use Select Tag the button passes an empty variable.

    When I swap out the Select Tag section for a simple Input Class=textfield, then it all works! Please see code snippet below.

    How do I get this working with a listbox or something like it?

    -Shogikishi



    ###DIV#1 button has onclick function to Workspace1(). This is where the controls are created as text and inserted into DIV#2 as innerHTML.

    ###The button in DIV#2 has onclick function to ChartType1(). When a InputClass of TextField is used, then it prints the value put in the textbox. When a Select Tag is used instead, it doesn't print the value.


    ###################
    public function Workspace1()
    {
    $this->Workspace1Controls();
    }
    # populate workspace1
    private function Workspace1Controls()
    //onMouseOver="alertselected()"
    {
    $var = (!empty($_REQUEST['selectSY']))?$_REQUEST['selectSY']:'';
    //$html .= '<form id="ChartType1Controls" name="ChartType1Controls" method="post" >';
    $html .= '<label for="selectSY">School Year </label><br/>';

    #############################
    # Want it as a listbox
    ##############################

    $html .= '<select name="selectSY" id="selectSY">
    <option value="'.$var.'">2003 - 2004</option>
    <option value="'.$var.'">2004 - 2005</option>
    <option value="'.$var.'">2005 - 2006</option>
    <option value="'.$var.'">2006 - 2007</option>
    <option value="'.$var.'" selected="selected">2007 - 2008</option></select>';

    ###########################
    # Try it as a text input field and it works!
    ############################
    //$html .= '<input class="textfield" type="text" name="selectSY" id="selectSY" value="'.$var.'" />';

    ##################
    $html .= '<input class="btnfield" type="button" id="chart1_btn" name="chart1_btn" value="Create Chart" onclick="'.$this->bindInline("ChartType1", "selectSY").'"/>';
    $html .= '</form>';

    //echo $this->htmlInner("controls",$html);
    echo $this->htmlInner("controls",$html);

    }




    ####################################
    # START PULL CHART TYPE 1
    #######################################
    public function ChartType1()
    {

    //selectedItem = this.ChartType1Controls.selectSY.selectedIndex;
    //selectedValue = this.ChartType1Controls.selectSY.options[selectedItem].value;
    $var = (!empty($_REQUEST['selectSY']))?$_REQUEST['selectSY']:'';

    if ($var=="")
    {
    echo "The variable container is empty";
    }

    $SY = $var;

    echo $SY." is the value";

    //echo include("../Chart1/Index.php");
    //echo include_once("../Chart1/Index.php");

    }
    Last edited by Shogikishi; 05-09-2008 at 01:34 AM. Reason: added cleared description of bug

  • #2
    New to the CF scene
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have stumbled (it really feels like I've bumbled my way through this over the last couple days) across a partial fix. Replacing "<option value="'.$var.'" " with "<option value=" and an integer, such as 1, gets the function working. The exception is when the option value is =0. When "=0" and the user selects that value, the function issues an empty variable. So "0" is not passing through. Any ideas?

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    As a temporary fix I have added an if statement to catch an empty variable (caused by 'option value=0'). It fills an empty variable with "0" and the function executes as intended.

    Why wouldn't <option value="0"> work?

    #####
    Updated ChartType1() function
    #####
    public function ChartType1()
    {

    //selectedItem = this.ChartType1Controls.selectSY.selectedIndex;
    //selectedValue = this.ChartType1Controls.selectSY.options[selectedItem].value;
    $var = (!empty($_REQUEST['selectSY']))?$_REQUEST['selectSY']:'';

    if ($var=="")
    {
    $var=0;

    } else {
    $var = $var;
    }
    $SY = $var;

    echo $SY." is the value";
    echo include("../Chart1/Index.php");
    //echo include_once("../Chart1/Index.php");

    }

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by Shogikishi View Post
    Why wouldn't <option value="0"> work?
    Because of this line:
    PHP Code:
    $var = (!empty($_REQUEST['selectSY']))?$_REQUEST['selectSY']:''
    Unless I'm missing something, that line is essentially meaningless, besides stripping that zero. From the php manual for empty:
    * "" (an empty string)
    * 0 (0 as an integer)
    * "0" (0 as a string)
    * NULL
    * FALSE
    * array() (an empty array)
    * var $var; (a variable declared, but without a value in a class)
    So, that line is saying: "If the request var is not empty, set $var to it. Otherwise, set it to empty." That's why I say it's meaningless.

    By the way, one of the top stickies in the forum says (with good reason) to wrap your code in appropriate tags - in the subject line, even. Really helps readability, which means it helps get responses, too.
    Last edited by tomws; 05-09-2008 at 03:51 AM. Reason: fixed bad tag, missing link

  • #5
    New to the CF scene
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks tomws. I'll look for the appropriate tags and use them next time.


  •  

    Posting Permissions

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