earthsiege
08-13-2005, 01:33 PM
Hi guys,
i had a problem a few weeks back trying to get 3 comboboxes working together, well i have to say that i scrapped that idea and am working on new scheme.
the code im writing now is two comboboxes where the second combobox is populated depending on what is chosen in the first combobox. Both arrays come from a database. This part of the script is working fine.
What i need now is to be able to get the selected values from the second MULTIPLE combobox (select1), turn them into a single text line and insert it into a input field (textbox).
so the part which i really need you to take a look at is the AddCat() function.
The code i have a the moment is like below,
<? include "../includes/connect.inc"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Accessible interdependent dropdowns</title>
<script language="JavaScript" type="text/javascript">
<!--
function popsel(choice){
var opts=new Array();
<?
$query1 = "select * from iyb_category";
$result1 = mysql_query($query1);
$number = mysql_num_rows($result1);
for ($i=1; $i < $number + 1; $i++){
$query2 = "select * from iyb_subCategory where cat_ids='$i'";
$result2 = mysql_query($query2);
print("opts[$i]=\"");
$numberB = mysql_num_rows($result2);
for ($z=0; $z < $numberB; $z++){
$subtype = mysql_result($result2,$z,"sub_category");
$subid = mysql_result($result2,$z,"sub_id");
print("$subid--$subtype,");
}
print("\".split(',');\n");
}
?>
document.forms[0].select1.options.length=0;
topop=opts[choice];
alert(choice);
document.forms[0].select1.options.length=topop.length;
for (i=0;i<topop.length;i++){
document.forms.oldexample.select1.options[i].text=topop[i];
}
}
function AddCat(){
var lol = document.forms[0].textbox;
var choices = document.forms[0].select1;
var r;
for (var i=0; i < choices.options.length; i++){
if (choices.options[i].selected)
r = r + " " + choices.options[i].text;
}
lol.value=r;
}
//-->
</script>
</head>
<body>
<table border="0" width="100%" summary="visual code examples">
<tr>
<td>
<form name="oldexample">
<table border="0">
<tr>
<td valign="top"><label for="choice">Choice</label></td>
<td>
<select name="choice" id="choice" size="10" onchange="popsel(this.options[this.selectedIndex].value)">
<?
$query1 = "select * from iyb_category";
$result1 = mysql_query($query1);
$A = mysql_num_rows($result1);
$type = mysql_result($result1,0,"cat_name");
for ($i=0; $i < $A; $i++){
$type= mysql_result($result1,$i,"cat_name");
$catid = mysql_result($result1,$i,"cat_id");
print("<option value='$catid' selected>$type</option>\n");
}
?>
</select>
</td>
<td valign="top">
<label for="select1">Options</label>
</td>
<td>
<select name="select1" size="10" id="select1">
<option value="s1_1">Choose a Choice</option>
</select>
</td>
<td>
<input type="button" class="button" onclick="Addcat()" value="Add >>" />
</td>
<td>
<input name="textbox">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
could ne1 help?
when i run the code this is the the html source code that i see:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Accessible interdependent dropdowns</title>
<script language="JavaScript" type="text/javascript">
<!--
function popsel(choice){
var opts=new Array();
opts[1]="1--plumber,2--carpenter,".split(',');
opts[2]="3--ISP,4--Hardware,".split(',');
opts[3]="5--Bank,".split(',');
document.forms[0].select1.options.length=0;
topop=opts[choice];
alert(choice);
document.forms[0].select1.options.length=topop.length;
for (i=0;i<topop.length;i++){
document.forms.oldexample.select1.options[i].text=topop[i];
}
}
function AddCat(){
var lol = document.forms[0].textbox;
var choices = document.forms[0].select1;
var r;
for (var i=0; i < choices.options.length; i++){
if (choices.options[i].selected)
r = r + " " + choices.options[i].text;
}
lol.value=r;
}
//-->
</script>
</head>
<body>
<table border="0" width="100%" summary="visual code examples">
<tr>
<td>
<form name="oldexample">
<table border="0">
<tr>
<td valign="top"><label for="choice">Choice</label></td>
<td>
<select name="choice" id="choice" size="10" onchange="popsel(this.options[this.selectedIndex].value)">
<option value='1' selected>Building</option>
<option value='2' selected>Computers</option>
<option value='3' selected>banking</option>
</select>
</td>
<td valign="top">
<label for="select1">Options</label>
</td>
<td>
<select name="select1" size="10" id="select1">
<option value="s1_1">Choose a Choice</option>
</select>
</td>
<td>
<input type="button" class="button" onclick="Addcat()" value="Add >>" />
</td>
<td>
<input name="textbox">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
i had a problem a few weeks back trying to get 3 comboboxes working together, well i have to say that i scrapped that idea and am working on new scheme.
the code im writing now is two comboboxes where the second combobox is populated depending on what is chosen in the first combobox. Both arrays come from a database. This part of the script is working fine.
What i need now is to be able to get the selected values from the second MULTIPLE combobox (select1), turn them into a single text line and insert it into a input field (textbox).
so the part which i really need you to take a look at is the AddCat() function.
The code i have a the moment is like below,
<? include "../includes/connect.inc"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Accessible interdependent dropdowns</title>
<script language="JavaScript" type="text/javascript">
<!--
function popsel(choice){
var opts=new Array();
<?
$query1 = "select * from iyb_category";
$result1 = mysql_query($query1);
$number = mysql_num_rows($result1);
for ($i=1; $i < $number + 1; $i++){
$query2 = "select * from iyb_subCategory where cat_ids='$i'";
$result2 = mysql_query($query2);
print("opts[$i]=\"");
$numberB = mysql_num_rows($result2);
for ($z=0; $z < $numberB; $z++){
$subtype = mysql_result($result2,$z,"sub_category");
$subid = mysql_result($result2,$z,"sub_id");
print("$subid--$subtype,");
}
print("\".split(',');\n");
}
?>
document.forms[0].select1.options.length=0;
topop=opts[choice];
alert(choice);
document.forms[0].select1.options.length=topop.length;
for (i=0;i<topop.length;i++){
document.forms.oldexample.select1.options[i].text=topop[i];
}
}
function AddCat(){
var lol = document.forms[0].textbox;
var choices = document.forms[0].select1;
var r;
for (var i=0; i < choices.options.length; i++){
if (choices.options[i].selected)
r = r + " " + choices.options[i].text;
}
lol.value=r;
}
//-->
</script>
</head>
<body>
<table border="0" width="100%" summary="visual code examples">
<tr>
<td>
<form name="oldexample">
<table border="0">
<tr>
<td valign="top"><label for="choice">Choice</label></td>
<td>
<select name="choice" id="choice" size="10" onchange="popsel(this.options[this.selectedIndex].value)">
<?
$query1 = "select * from iyb_category";
$result1 = mysql_query($query1);
$A = mysql_num_rows($result1);
$type = mysql_result($result1,0,"cat_name");
for ($i=0; $i < $A; $i++){
$type= mysql_result($result1,$i,"cat_name");
$catid = mysql_result($result1,$i,"cat_id");
print("<option value='$catid' selected>$type</option>\n");
}
?>
</select>
</td>
<td valign="top">
<label for="select1">Options</label>
</td>
<td>
<select name="select1" size="10" id="select1">
<option value="s1_1">Choose a Choice</option>
</select>
</td>
<td>
<input type="button" class="button" onclick="Addcat()" value="Add >>" />
</td>
<td>
<input name="textbox">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
could ne1 help?
when i run the code this is the the html source code that i see:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Accessible interdependent dropdowns</title>
<script language="JavaScript" type="text/javascript">
<!--
function popsel(choice){
var opts=new Array();
opts[1]="1--plumber,2--carpenter,".split(',');
opts[2]="3--ISP,4--Hardware,".split(',');
opts[3]="5--Bank,".split(',');
document.forms[0].select1.options.length=0;
topop=opts[choice];
alert(choice);
document.forms[0].select1.options.length=topop.length;
for (i=0;i<topop.length;i++){
document.forms.oldexample.select1.options[i].text=topop[i];
}
}
function AddCat(){
var lol = document.forms[0].textbox;
var choices = document.forms[0].select1;
var r;
for (var i=0; i < choices.options.length; i++){
if (choices.options[i].selected)
r = r + " " + choices.options[i].text;
}
lol.value=r;
}
//-->
</script>
</head>
<body>
<table border="0" width="100%" summary="visual code examples">
<tr>
<td>
<form name="oldexample">
<table border="0">
<tr>
<td valign="top"><label for="choice">Choice</label></td>
<td>
<select name="choice" id="choice" size="10" onchange="popsel(this.options[this.selectedIndex].value)">
<option value='1' selected>Building</option>
<option value='2' selected>Computers</option>
<option value='3' selected>banking</option>
</select>
</td>
<td valign="top">
<label for="select1">Options</label>
</td>
<td>
<select name="select1" size="10" id="select1">
<option value="s1_1">Choose a Choice</option>
</select>
</td>
<td>
<input type="button" class="button" onclick="Addcat()" value="Add >>" />
</td>
<td>
<input name="textbox">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>