SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript + Browser Issue

    Hi all,

    I am using a php/Javascript file that displays data based on a users select menu selection.

    It works fine on my PC but another person sees XXXXXXX displayed as the loaded content on their PC.

    Any ideas why this is? Checked Security Settings on IE6 and Active Scripting is enabled.

    Thanks.

    PHP Code:
         /*
         ** Class: chainedSelectors
         ** Description: This class allows you to create two selectors.  Selections
         ** made in the first selector cause the second selector to be updated.
         ** PHP is used to dynamically create the necessary JavaScript.
         */
         
         //These constants make the code a bit more readable.  They should be
         //used in in the creation of the input data arrays, too.
         
    define("CS_FORM"0);
         
    define("CS_FIRST_SELECTOR"1);
         
    define("CS_SECOND_SELECTOR"2);
         
         
    define("CS_SOURCE_ID"0);
         
    define("CS_SOURCE_LABEL"1);
         
    define("CS_TARGET_ID"2);
         
    define("CS_TARGET_LABEL"3);
         
         class 
    chainedSelectors
         
    {
             
    /*
             ** Properties
             */
             
             //Array of names for the form and the two selectors.
             //Should take the form of array("myForm", "Selector1", "Selector2")
             
    var $names;
             
             
    //Array of data used to fill the two selectors
             
    var $data;
             
             
    //Unique set of choices for the first selector, generated on init
             
    var $uniqueChoices;
             
             
    //Calculated counts
             
    var $maxTargetChoices;
             var 
    $longestTargetChoice;
     
     
             
    /*
             ** Methods
             */
             
             //constructor
             
    function chainedSelectors($names$data)
             {
                 
    /*
                 **copy parameters into properties
                 */
                 
    $this->names $names;
                 
    $this->data $data;
     
                 
    /*
                 ** traverse data, create uniqueChoices, get limits
                 */        
                 
    foreach($data as $row)
                 {
                     
    //create list of unique choices for first selector
                     
    $this->uniqueChoices[($row[CS_SOURCE_ID])] = $row[CS_SOURCE_LABEL];    
     
                     
    //find the maximum choices for target selector
                     
    $maxPerChoice[($row[CS_SOURCE_ID])]++;
                     
                     
    //find longest value for target selector
                     
    if(strlen($row[CS_TARGET_LABEL]) > $this->longestTargetChoice)
                     {
                         
    $this->longestTargetChoice=strlen($row[CS_TARGET_LABEL]);
                     }
                 }
                 
                 
    $this->maxTargetChoices max($maxPerChoice);
             }
     
             
    //prints the JavaScript function to update second selector
             
    function printUpdateFunction()
             {
                 
    /*
                 ** Create some variables to make the code
                 ** more readable.
                 */
                 
    $sourceSelector "document." $this->names[CS_FORM] . "." 
                     
    $this->names[CS_FIRST_SELECTOR];
                 
    $targetSelector "document." $this->names[CS_FORM] . "." 
                     
    $this->names[CS_SECOND_SELECTOR];
             
                 
    /*
                 ** Start the function
                 */
                 
    print("function update" .$this->names[CS_SECOND_SELECTOR] . "()\n");
     
                 print(
    "{\n");
     
                 
    /*
                 ** Add code to clear out next selector
                 */
                 
    print("\t//clear " $this->names[CS_SECOND_SELECTOR] . "\n");
                 print(
    "\tfor(index=0; index < $this->maxTargetChoices; index++)\n");
                 print(
    "\t{\n");
                 print(
    "\t\t" $targetSelector ".options[index].text = '';\n");
                 print(
    "\t\t" $targetSelector ".options[index].value = '';\n");
                 print(
    "\t}\n\n");
                 print(
    "\t" $targetSelector ".options[0].selected = true;\n\n");
     
                 
    /*
                 ** Add code to find which was selected
                 */
                 
    print("whichSelected = " $sourceSelector ".selectedIndex;\n");
     
                 
    /*
                 ** Add giant "if" tree that puts values into target selector
                 ** based on which selection was made in source selector
                 */
     
                 //loop over each value of this selector
                 
    foreach($this->uniqueChoices as $sourceValue=>$sourceLabel)
                 {
                     print(
    "\tif(" $sourceSelector .
                         
    ".options[whichSelected].value == " .
                         
    "'$sourceValue')\n");
                     print(
    "\t{\n");
     
                     
    $count=0;
                     foreach(
    $this->data as $row)
                     {
                         if(
    $row[0] == $sourceValue)
                         {
                             
    $optionValue $row[CS_TARGET_ID];
                             
    $optionLabel $row[CS_TARGET_LABEL];
     
                             print(
    "\t\t" $targetSelector .
                                 
    ".options[$count].value = '$optionValue';\n");
                             print(
    "\t\t" $targetSelector .
                                 
    ".options[$count].text = '$optionLabel';\n\n");
     
                             
    $count++;
                         }
                     }
     
                     print(
    "\t}\n\n");
                 }
     
                 print(
    "\treturn true;\n");
                 print(
    "}\n\n");
     
             }
     
             
    //print the two selectors
             
    function printSelectors()
             {
                 
    /*
                 **create prefilled first selector
                 */
                 
    $selected=TRUE;
                 print(
    "<select name=\"" $this->names[CS_FIRST_SELECTOR] . "\" " .
                     
    "onChange=\"update".$this->names[CS_SECOND_SELECTOR]."();\">\n");
                             
                             
    //echo '<option value="none">Select Date</option>';        
                             
                 
    foreach($this->uniqueChoices as $key=>$value)
                 {
                     print(
    "\t<option value=\"$key\"");
                     if(
    $selected)
                     {
                         print(
    " selected=\"selected\"");
                         
    $selected=FALSE;
                     }
                     print(
    ">$value</option>\n");
                 }
                 print(
    "</select>\n");
                             
    //echo '<br /><br />';
     
                 /*
                 **create empty target selector
                 */
                 
    $dummyData str_repeat("X"$this->longestTargetChoice);
                 
                             echo 
    '<p><label for="class_time" class="lbl_time">Class Ends:</label>';
                 print(
    "<select name=\"".$this->names[CS_SECOND_SELECTOR]."\">\n");
                             
                 for(
    $i=0$i $this->maxTargetChoices$i++)
                 {
                     print(
    "\t<option value=\"\">$dummyData</option>\n");
                 }
                 print(
    "</select></p>");
                             
    //echo '<br />';
                             
             
    }
             
             
    //prints a call to the update function
             
    function initialize()
             {
                 print(
    "update" .$this->names[CS_SECOND_SELECTOR] . "();\n");
             }
         } 

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So how about showing some front-end code instead of the PHP?

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the <head>...

    <script type="text/javascript" language="JavaScript">
    <?php
    $areacode->printUpdateFunction();
    ?>
    </script>

    then at end of page...

    <script type="text/javascript" language="JavaScript">
    <?php
    $areacode->initialize();
    ?>
    </script>

    Think that's where the problem lies. The 2nd selector isn't initialised.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again, show us what the php outputted in the browser instead of showing PHP code

  5. #5
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the View Source code...
    Code:
     <head>
     <title>Home</title>
     
     <script type="text/javascript" language="JavaScript">
     function updateclass_end()
     {
     	//clear class_end
     	for(index=0; index < 10; index++)
     	{
     		document.pickAreaCode.class_end.options[index].text = '';
     		document.pickAreaCode.class_end.options[index].value = '';
     	}
     
     	document.pickAreaCode.class_end.options[0].selected = true;
     
     whichSelected = document.pickAreaCode.class_start.selectedIndex;
     	if(document.pickAreaCode.class_start.options[whichSelected].value == 'Aug 14 2006  9:30AM')
     	{
     		document.pickAreaCode.class_end.options[0].value = 'Aug 18 2006  5:00PM';
     		document.pickAreaCode.class_end.options[0].text = 'Aug 18 2006  5:00PM';
     
     	}
     	return true;
     }
     
     </script>
     
     </head>
     <body>
     
     <form action="reg_staff3.php" name="pickAreaCode" method="post">
     		<fieldset>
     			 <legend>Register Staff</legend>
     					
     			 
     			 <p>
     			  <label for="class_date" class="lbl_time">Class Starts:</label>
     			 <select name="class_start" onChange="updateclass_end();">
     	<option value="Aug 14 2006  9:30AM" selected="selected">Aug 14 2006  9:30AM</option>
     	<option value="Jul 17 2006  9:30AM">Jul 17 2006  9:30AM</option>
     	<option value="May 15 2006 12:00AM">May 15 2006 12:00AM</option>
     	<option value="Mar 20 2006 12:00AM">Mar 20 2006 12:00AM</option>
     	<option value="Feb 20 2006 12:00AM">Feb 20 2006 12:00AM</option>
     	<option value="Nov 14 2005 12:00AM">Nov 14 2005 12:00AM</option>
     	<option value="Aug 15 2005 12:00AM">Aug 15 2005 12:00AM</option>
     	<option value="Jun 13 2005 12:00AM">Jun 13 2005 12:00AM</option>
     	<option value="May 16 2005 12:00AM">May 16 2005 12:00AM</option>
     	<option value="Jan 17 2005 12:00AM">Jan 17 2005 12:00AM</option>
     </select>
     <p><label for="class_time" class="lbl_time">Class Ends:</label><select name="class_end">
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     	<option value="">XXXXXXXXXXXXXXXXXXX</option>
     </select></p>			 </p>
     
     			 <!-- PASS ARRAY DETAILS -->
     		    			  <input type="hidden" name="ffnumber[]" value="ff19219-Barden-Bridget" />
     		    			  <input type="hidden" name="location" value="3" />
     			 <input type="hidden" name="course" value="82" />
     
     			 <p>
     			  <input type="submit" name="submit" id="submit" class="btn" value="Continue" />
     			 </p>
     
     
     		</fieldset>
     
     </form>
     
     
     <script type="text/javascript" language="JavaScript">
     updateclass_end();
     </script

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not so sure this is a JavaScript issue though, since this other persons get all these XXXX and you not. Might be a encodnig issue? You guys have the same encoding settings in the browser?

  7. #7
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I check encoding settings?


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
  •