Page 1 of 1

required help to load dynamic combo using php

Posted: Tue Jul 25, 2006 1:41 am
by jameswatt
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi

i have Two combo Combo A and Combo B
Combo A contains dynamic data from database now if user select any row or index from Combo A and press ADD button that DATA would be add to Combo B, i have written following code but do not work while ADDing data from combo A to Combo B i gets javascript error like object is null....

Code: Select all

<?
require_once("class/connection.php"); 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>

function a()
{
document.frmsizematrix.s2.remove(0);
}

function add(x)
{

//alert("Value of x is :" + x);
var boxLength;
var selectedItem;
var selectedText;
var selectedValue;
var i;
var thisitem;
var isNew = true;


if ( x == 0)
{

boxLength = document.frmsizematrix.s2.length;
selectedItem = document.frmsizematrix.s1.selectedIndex;
selectedText = document.frmsizematrix.s1.options[selectedItem].text;
selectedValue = document.frmsizematrix.s1.options[selectedItem].value;
}

if ( x == 1)
{
boxLength = document.frmsizematrix.s2.length;
selectedText = document.frmsizematrix.t1.value;
}
//var newoption;
//document.frmsizematrix.t1.value = x;//boxLength;

if (boxLength != 0)
{
for (i = 0; i < boxLength; i++)
{
if ( selectedText == document.frmsizematrix.s2.options[i].text)
{
isNew = false;
break;
}
}
}

if (isNew == true)
{
document.frmsizematrix.s2.options[boxLength] = new Option(selectedText,boxLength);
}
}

function rmv()
{
var selectedItem;
selectedItem = document.frmsizematrix.s2.selectedIndex;
document.frmsizematrix.s2.remove(selectedItem);
}

</script>



</head>

<body  onload="a();">
<form name="frmsizematrix" method="post" action="SizeMatrixprocess.php">
<table width="69%" border="1" cellpadding="1" cellspacing="1" align="center" class="text">
<tr>
	<td colspan="2" align="center"><b><font color="#0000FF">Add Width for Selected Item</font></b></td>
</tr>
  <tr>
    <td>Add Size Style Name :</td>
	
    <td>&nbsp;<input type="text" name="txtSizematrix"></td>
  </tr>
  <tr>
    <td width="25%">&nbsp;Size</td>
    <td width="75%"><table width="283" align="center">
        <tr>
          <td align="center">Available Sizes</td>
          <td></td>
          <td align="center">Assign Sizes</td>
        </tr>
        <tr>
          <td><?
		  	$sql="select * from tblsizemst";
			$rs = mysql_query($sql);
			$num = mysql_num_rows($rs);
			//echo $sql;
			//echo $num;
			//$i=0;
			?>
            <select   name="s1[]" size="6" multiple id="select"  >
	 <?
	 while($row = mysql_fetch_array($rs))
	 {
	 				$sizeId=$row[0];
					$SizeName=$row[1];
  	        	    echo"<option value=$SizeName>$SizeName</option>";

  	 }							
		
	?>		  
            </select>          </td>
 <td align="center"><input type="button" value="ADD" name="b1" onClick="add(0);">
              <br>
              <br>
              <input type="button" value="Remove" name="b3" onclick="rmv();" /></td>
          <td>
		  <select name="s2" size="6" multiple="multiple">
          	  <option ></option>
          </select>		  </td>
        </tr>
        <tr> </tr>
    </table></td>
  </tr>
  <? 
									//}
								//End of if condition
					?>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="btnadd" value="Save Size">
      &nbsp;<input type="button" value="Cancel" onclick="window.close();"  name="button">
    </td>
  </tr>
</table>
</form>
</body>

</html>

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

Re: required help to load dynamic combo using php

Posted: Tue Jul 25, 2006 2:26 am
by RobertGonzalez
jameswatt, please use the appropriate bbCode tags when posting code. Also, pick the right forum for posting. This belongs in client-side.

Posted: Tue Jul 25, 2006 3:08 am
by JayBird
Moved to Client Side