469,336 Members | 5,299 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

list menu problem

hi friends

i am very new to java script.if anyone can help me out then
i will be thankful.

i am using php and mysql in my learning project and i have
two list boxes,now whenever user presses first listbox i mean user
selects listbox then approprieate records should be come in second
listbox.can i do it with javascript? i.e if user selects list item
'class bca' then all the records related to 'class bca' should come to
second listbox.i wants to store records in 3*3 array in javascript
first then i wants to use it. but i am unsuccessfull so i need your
help friends.
Bye & Best Of Luck.

Apr 17 '06 #1
6 1706
Post existing source code and we'll see.
Apr 17 '06 #2
<?php require_once('../Connections/admin.php'); ?>
<?php if($_GET['tb']==1)
{
$tablename="card";
}
else if ($_GET['tb']==2){
$tablename="gift";
}
?>
<?php
mysql_select_db($database_admin, $admin);
$query_Recordset1 = "SELECT $tablename_cat.cat_id, <?php echo
$tablename; ?>_cat.cat_name FROM <?php echo $tablename; ?>_cat";
$Recordset1 = mysql_query($query_Recordset1, $admin) or
die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_admin, $admin);
$query_Recordset2 = "SELECT <?php echo $tablename; ?>_subcat.cat_id,
<?php echo $tablename; ?>_subcat.subcat_id, <?php echo $tablename;
?>_subcat.name FROM <?php echo $tablename; ?>_subcat";
$Recordset2 = mysql_query($query_Recordset2, $admin) or
die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form>

<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Category Name </td>
<td><input type="text" name="cat_name"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="Add Category">
</div></td>
</tr>
</table>
</form>
<form>
<p>&nbsp;</p>
<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Sub Category</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Category</td>
<td><select name="select">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['cat_id']?>"<?php if
(!(strcmp($row_Recordset1['cat_id'], $row_Recordset1['cat_name'])))
{echo "selected=\"selected\"";} ?>><?php echo
$row_Recordset1['cat_name']?></option><?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>.
</select></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Add Sub Category">
</div></td>
</tr>
</table>
</form>

<p>&nbsp;</p>

<table width="349" border="1" cellspacing="0" cellpadding="0">
<form action="$addform.php">
<tr>
<td width="131">Category</td>
<td width="212"><select name="select2">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['cat_id']?>"<?php if
(!(strcmp($row_Recordset1['cat_id'], $row_Recordset1['cat_name'])))
{echo "selected=\"selected\"";} ?>><?php echo
$row_Recordset1['cat_name']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select></td>
</tr>
</form>
<form>
<tr>
<td>Sub Category </td>
<td><select name="select3">
<?php
do {
?>
<option value="<?php echo $row_Recordset2['subcat_id']?>"<?php if
(!(strcmp($row_Recordset2['subcat_id'], $row_Recordset2['name'])))
{echo "selected=\"selected\"";} ?>><?php echo
$row_Recordset2['name']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>

Apr 18 '06 #3
hardik said on 18/04/2006 2:23 AM AEST:
hi friends

i am very new to java script.if anyone can help me out then
i will be thankful.

i am using php and mysql in my learning project and i have
two list boxes,now whenever user presses first listbox i mean user
selects listbox then approprieate records should be come in second
listbox.can i do it with javascript? i.e if user selects list item
'class bca' then all the records related to 'class bca' should come to
second listbox.i wants to store records in 3*3 array in javascript
first then i wants to use it. but i am unsuccessfull so i need your
help friends.


This is not chat. Please use correct punctuation and capitalisation in
your posts. You've taken the time to double-space paragraphs and indent
the first line, so is the chat-style just to be hip?

Anyhow, I presume you mean you have your data in an array object like:

var theData = [
['A1','A2','A3'],
['B1','B2','B3'],
['C1','C2','C3']
];

You don't say what values you intend putting in the first select
element, nor how the values for the second are chosen. I'll presume
that you want to put A1, B1 and C1 as the values of options in your
first select, and the rest of the associated array in the second select
depending on which one is chosen in the first.

For example (lacking feature detection and fallback...):
<title>Select play</title>

<script type="text/javascript">

/* Data matrix
*/
var theData = [
['A1','A2','A3'],
['B1','B2','B3'],
['C1','C2','C3']
];

/* Load the first select with options
*/
function initSel(sel)
{
// Remove current options
sel.options.length = 0;
var val;

// Insert one option for each array in theData
for (var i=0, len=theData.length; i<len; ++i){

// Use the first element in each array as the value & text
val = theData[i][0];
sel.options[i] = new Option(val, val);
}
}

/* selA is a reference to the source select
* selB is a reference to the select to update
*/
function fillSel(selA, selB)
{
// Get the value of the selected option
var val = selA[selA.selectedIndex].value;
var valArray, valB;

// Find which array the value came from (the value
// of the first item in each array must be unique)
for (var i=0, len=theData.length; i<len; ++i){
valArray = theData[i];

// When a match found, use the rest of the array items
// to set the second select's option value & text
if (valArray[0] == val){
selB.options.length = 0;
for (var j=1, m=valArray.length; j<m; ++j){
valB = valArray[j];
selB.options[j-1] = new Option(valB, valB);
}
}
}
}

</script>

</head>
<body onload="initSel(document.formA.sel_1);">

<form name="formA" action="">
Option 1
<select name="sel_1" style="width:13em"
onchange="fillSel(this, this.form.sel_2);">
<option>JavaScript required
</select>
Option 2
<select name="sel_2" style="width:13em">
<option>Select option 1 first
</select>
</form>

</body>

--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 18 '06 #4
u r cool

Apr 18 '06 #5
hardik wrote:
u r cool


You are not. Could you please go away silently? Now?
PointedEars
Apr 18 '06 #6
Thomas 'PointedEars' Lahn wrote:
hardik wrote:
u r cool


You are not.


Shouldn't that be

U R !
Apr 19 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Adam Smith | last post: by
1 post views Thread by platostoteles | last post: by
16 posts views Thread by stevedude | last post: by
4 posts views Thread by shapper | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.