Notice: Undefined index: Scales ...but it is defined? :S

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ChrisPintys
    New Member
    • Aug 2010
    • 20

    #16
    Ahhh, that's a good idea actually, and I don't see the drop-down being populated in HTML, so I guess that is my problem :(

    Code:
     <select size="1" name="itemType1" onChange="getCity('material1','findcity.php?itemType='+this.value)"><option selected 
            value=""></option> <option value="M">Material</option><option value="1">PH1</option> <option 
            value=2>PH2</option> <option value="3">PH3</option> <option 
            value=4>PH4</option> &lt;\SELECT&gt;</select>
    ItemType1 is selected, which then calls a function which populates the drop down, city1.

    Code:
    <span id="material1">
    <select style="width: 158px;" onclick="this.style.width='340px';this.size='10'" onmouseout="this.style.width='158px';this.size=''" class="widthed" name="city1" id="city1">
     </select>    </span>
    I can see all of the values in the drop down, but it doesn't look like the values are anywhere in the HTML...now I am really confused.

    Comment

    • JKing
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #17
      That's because the ajax adds in the text after the html has been posted to the browser.

      You will need to grab the HTML from the file the AJAX is calling. Have a look in there and make sure it is formatted properly with values for each option in the select.

      Alternatively you could use Firebug which is a browser addon to inspect the HTML after it has been changed by the javascript.

      Comment

      • ChrisPintys
        New Member
        • Aug 2010
        • 20

        #18
        THANK YOU, that makes sense to me, I'll take a look and report back (possibly not until monday).

        Comment

        • ChrisPintys
          New Member
          • Aug 2010
          • 20

          #19
          Ok, I've found the problem, and spend the past couple hours trying to solve it, but I'm just not getting it. If anyone could give me a pointer that would be awesome

          I have my first drop down, which when selected runs the getcity function:

          Code:
          <select size="1" name="itemType1" onChange="getCity('material1','findcity.php?matNum=citys1&itemType='+this.value)"><option selected 
                  value=""></option> <option value="M">Material</option><option value="1">PH1</option> <option 
                  value=2>PH2</option> <option value="3">PH3</option> <option 
                  value=4>PH4</option> &lt;\SELECT&gt;</select>           
                 <span id="material1">
          <select style="width: 158px;" onclick="this.style.width='340px';this.size='10'" onmouseout="this.style.width='158px';this.size=''" class="widthed" name="city1" id="city1">
           </select>    </span>
          The getcity function:

          Code:
          	function getCity($elementID,strURL) {		
          		
          		var req = getXMLHTTP();
          		
          		if (req) {
          			
          			req.onreadystatechange = function() {
          				if (req.readyState == 4) {
          					// only if "OK"
          					if (req.status == 200) {						
          						document.getElementById($elementID).innerHTML=req.responseText;						
          					} else {
          						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
          					}
          				}				
          			}			
          			req.open("GET", strURL, true);
          			req.send(null);
          		}
          And the page that it calls, this has the code that replaces the drop down I have, with the dynamic content, the only problem is, I have 10 of these drop downs, so this function is called each time one is selected, I'm not sure how to have the NAME of the drop down dynamic, for example, the first drop down be called city1, the next city2, etc.. I can manually set the name to be city1, and the first drop down will work great, but none of the others will.

          Specifically this line in the below code:

          Code:
          <select style="width: 158px;" onclick="this.style.width='340px';this.size='10'" onmouseout="this.style.width='158px';this.size=''" class="widthed" name=<?php"'.$matNum1.'"?>>
          You can see I have the name=$matNum1 .. hoping it would pull the "citys1" name I passed it from the previous page, but that's not working, I just need to get this name being dynamic so each time I call this function, it uses the same name as the drop down it is replacing.

          The full findcity.php code:

          Code:
          <?php $itemType=$_GET['itemType'];
          $matNum1=$_GET['matNum'];
          
          function sqlSelect($daisySelect)
          {
            //connect to a DSN, "daisy" 
          $conn = odbc_connect('daisy','chrisbwamp',''); 
          if ($conn) 
          { 
            //The SQL statement that will query the database 
            $query = $daisySelect; 
          
            //Perform the query 
            $result=odbc_exec($conn, $query); 
          
            //Convert results to an array
            while(odbc_fetch_row($result))
            { 
               for($i=1;$i<=odbc_num_fields($result);$i++)  
                    {
                       $selectArray[]=odbc_result($result,$i);
                    }
            } 
          return $selectArray;
          }
           else echo "ODBC not connected, please contact ITHelpdesk@pintys.com, reference Chris Beach";  
          }
          
          if ( $itemType == "M" ) 
          	$arrProductNum=sqlSelect("SELECT Material_ID + ' - ' + DESCRIPTION AS Expr1 FROM VW_TradeSpend_Material ORDER BY Material_ID ASC");
          elseif( $itemType == "1" )
                $arrProductNum=sqlSelect("SELECT DISTINCT LEVEL1_DESC FROM pintys.PROD_HIERARCHY");
          elseif( $itemType == "2" )
                $arrProductNum=sqlSelect("SELECT DISTINCT LEVEL2_DESC FROM pintys.PROD_HIERARCHY");
          elseif( $itemType == "3" )
                $arrProductNum=sqlSelect("SELECT DISTINCT LEVEL3_DESC FROM pintys.PROD_HIERARCHY");
          elseif( $itemType == "4" )
                $arrProductNum=sqlSelect("SELECT DISTINCT LEVEL4_DESC FROM pintys.PROD_HIERARCHY");
          ?>
          
          <select style="width: 158px;" onclick="this.style.width='340px';this.size='10'" onmouseout="this.style.width='158px';this.size=''" class="widthed" name=<?php"'.$matNum1.'"?>>
          <option></option>
          
          <?php
          foreach($arrProductNum as $products) { 
          echo'<option value="'.$products.'">'.ltrim($products,"0").'</option>'; } 
                echo "</select>"; 
          ?>
          I've attempted to send the word "citys1" in my drop down in my own form, and have the "findcity.p hp" pick it up as matNum1, and use it as the "name" so it could be dynamic, but it's not working :(

          Comment

          • ChrisPintys
            New Member
            • Aug 2010
            • 20

            #20
            Got it! :)

            I used an HTML array (I didn't know they existed), this solved that problem.

            Thanks for all the help.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #21
              what is an HTML array?

              Comment

              • ChrisPintys
                New Member
                • Aug 2010
                • 20

                #22
                I take it by your answer, no such thing exists :p

                I'm new to all of this, so not sure the proper name, but I basically set the name of my drop down box as:

                Code:
                name="citysTest[]"
                Which seems to act as an array, and increment each time the ajax is called, so then when uploading all of the values through PHP, I'm able to reference
                Code:
                $citysTesting = $_POST['citysTest'];
                And then loop through uploading each value of the drop down boxes

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #23
                  I'm new to all of this, so not sure the proper name, but I basically set the name of my drop down box as:

                  Code:
                  name="citysTest[]"
                  yepp, that’s the way to tell PHP that it should put these elements in an array.

                  Comment

                  Working...