5 Replies - 423 Views - Last Post: 04 August 2012 - 01:54 AM Rate Topic: -----

#1 airy  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 22
  • Joined: 11-July 12

Unable to select dropdownlist options :(

Posted 03 August 2012 - 12:25 AM

Why couldn't i select the option in drop down list

<?php
if (!defined('WEB_ROOT')) {
	exit;
}

$catId = (isset($_GET['catId']) && $_GET['catId'] > 0) ? $_GET['catId'] : 0;

$categoryList = buildCategoryOptions($catId);
?> 
<p>&nbsp;</p>
<form action="processProduct.php?action=addProduct" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
  <tr><td colspan="2" id="entryTableHeader">Add Product</td></tr>
  <tr> 
   <td width="150" class="label">Category</td>
   <td class="content"> <select name="cboCategory" id="cboCategory" class="box">
     <option value="" selected>-- Choose Category --</option>
<?php
	echo $categoryList;
?>	 
    </select></td>
  </tr>
  <tr> 
   <td width="150" class="label">Product Name</td>
   <td class="content"> <input name="txtName" type="text" class="box" id="txtName" size="50" maxlength="100"></td>
  </tr>
  <tr> 
   <td width="150" class="label">Description</td>
   <td class="content"> <textarea name="mtxDescription" cols="70" rows="10" class="box" id="mtxDescription"></textarea></td>
  </tr>
  <tr> 
   <td width="150" class="label">Price</td>
   <td class="content"><input name="txtPrice" type="text" id="txtPrice" size="10" maxlength="7" class="box" onkeyup="checkNumber(this);"> </td>
  </tr>
  <tr> 
   <td width="150" class="label">Qty In Stock</td>
   <td class="content"><input name="txtQty" type="text" id="txtQty" size="10" maxlength="10" class="box" onkeyup="checkNumber(this);"> </td>
  </tr>
  <tr> 
   <td width="150" class="label">Image</td>
   <td class="content"> <input name="fleImage" type="file" id="fleImage" class="box"> 
    </td>
  </tr>
 </table>
 <p align="center"> 
  <input name="btnAddProduct" type="button" id="btnAddProduct" value="Add Product" onclick="checkAddProductForm();" class="box">
  &nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onclick="window.location.href='index.php';" class="box">  
 </p>
</form>



Is This A Good Question/Topic? 0
  • +

Replies To: Unable to select dropdownlist options :(

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3043
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: Unable to select dropdownlist options :(

Posted 03 August 2012 - 01:23 AM

Based on that, there is no way for us to know. The HTML looks solid (if a tad outdated), so I must assume that the problem is with the buildCategoryOptions() function, which you didn't show us.

Why don't you start by showing us the HTML output that is being sent to the browser, after the PHP is executed.
Was This Post Helpful? 0
  • +
  • -

#3 airy  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 22
  • Joined: 11-July 12

Re: Unable to select dropdownlist options :(

Posted 03 August 2012 - 02:02 PM

here's this code.
hmmm, i don't really understand

Quote

Why don't you start by showing us the HTML output that is being sent to the browser, after the PHP is executed.


the code above , i believe that was beginning of the code. 
function buildCategoryOptions($catId = 0)
{
	$sql = "SELECT cat_id, cat_parent_id, cat_name
			FROM tbl_category
			ORDER BY cat_id";
	$result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error());
	
	$categories = array();
	while($row = dbFetchArray($result)) {
		list($id, $parentId, $name) = $row;
		
		if ($parentId == 0) {
			// we create a new array for each top level categories
			$categories[$id] = array('name' => $name, 'children' => array());
		} else {
			// the child categories are put int the parent category's array
			$categories[$parentId]['children'][] = array('id' => $id, 'name' => $name);	
		}
	}	
	


sorry these are the codes

function buildCategoryOptions($catId = 0)
{
	$sql = "SELECT cat_id, cat_parent_id, cat_name
			FROM tbl_category
			ORDER BY cat_id";
	$result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error());
	
	$categories = array();
	while($row = dbFetchArray($result)) {
		list($id, $parentId, $name) = $row;
		
		if ($parentId == 0) {
			// we create a new array for each top level categories
			$categories[$id] = array('name' => $name, 'children' => array());
		} else {
			// the child categories are put int the parent category's array
			$categories[$parentId]['children'][] = array('id' => $id, 'name' => $name);	
		}
	}	
	
	// build combo box options
	$list = '';
	foreach ($categories as $key => $value) {
		$name     = $value['name'];
		$children = $value['children'];
		
		$list .= "<optgroup label=\"$name\">"; 
		
		foreach ($children as $child) {
			$list .= "<option value=\"{$child['id']}\"";
			if ($child['id'] == $catId) {
				$list.= " selected";
			}
			
			$list .= ">{$child['name']}</option>\r\n";
		}
		
		$list .= "</optgroup>";
	}
	
	return $list;
}


Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3043
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: Unable to select dropdownlist options :(

Posted 03 August 2012 - 09:48 PM

View Postairy, on 03 August 2012 - 09:02 PM, said:

hmmm, i don't really understand

Quote

Why don't you start by showing us the HTML output that is being sent to the browser, after the PHP is executed.

What I mean is, the PHP code is executed on the server and it generates HTML markup that is then sent to the browser where it is displayed. It would help to see the HTML markup that PHP generated.

To find that, just open the site in your browser, right click on the page and select: "View Page Source" (Firefox/Chrome), "View Source" (IE), or "Source" (Opera).
Was This Post Helpful? 0
  • +
  • -

#5 airy  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 22
  • Joined: 11-July 12

Re: Unable to select dropdownlist options :(

Posted 04 August 2012 - 01:25 AM

OHhh, is this the one?
<td class="label" width="150">Category</td>
<td class="content">
<select id="cboCategory" class="box" name="cboCategory">
<option selected="" value="">-- Choose Category --</option>
<optgroup label="Tops"></optgroup>
<optgroup label="Dress"></optgroup>
<optgroup label="Sweater"></optgroup>
</select>
</td>


hmmm? is there anything wrong? i cant figure out
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3043
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: Unable to select dropdownlist options :(

Posted 04 August 2012 - 01:54 AM

I'm going to go ahead and assume, then, that you wrote none of this yourself? How much PHP, HTML and SQL do you actually know?

To answer your question: Yes, there is something wrong with that HTML: There are no options. - It should be obvious to anybody who knows what that code is supposed to be doing.

As far as I can see, the PHP code should work, so my guess is that there is some issue with the data. To figure out what that problem is, you may want to start by dumping the contents of the $categories array in the function that builds the options, after the while loop creates it, to find out what data you're working with.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1