473,390 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 1864
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Adam Smith | last post by:
I am developing a Form to be used for data input into a database. To limit errors in fields I want to input some data using "<SELECT NAME=xxxxx> <OPTIONS VALUE=yyyyy> <OPTIONS VAL........> ..........
1
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that...
1
by: Andi | last post by:
Using a DHTML dropdown menu, blocks of menu items should be displayed on top of the page to let the user choose a menu item. So, on top of my page (no matter how it is constructed), there should...
2
by: TheRomance | last post by:
i have a problem about insert integer to link list. sorry it's too long but i try many times, many ways , it's still have an error function is fix . can't change anything about function. i...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
4
by: shapper | last post by:
Hello, I am creating a simple List Menu where when a mouse is over a button the background changes: http://www.27lamps.com/public/Menu.htm Why do I get a white space between each menu item? ...
5
by: jmartmem | last post by:
Greetings, I am using Dreamweaver CS3 to design an ASP page that contains an Insert Record Form. Within this form are two list/menu form fields that I would like to "synchronize". In other words,...
5
n8kindt
by: n8kindt | last post by:
hi, i have a selection list that has 150 options in it. in firefox i have no problem with my current set up. when u click on the list box, the menu drops down. but in internet explorer, the menu goes...
10
by: lenzie | last post by:
I am having a very odd problem with a website I run. The menus have recently been changed to use javascript and some people are reporting that when they first use the site, Instead of a nicely...
0
by: rahullko05 | last post by:
i have designed a menu list program in which i'm facing a problem where the last li item (white crappie) shifts down when i hover mouse pointer to just above li item (ozrack bazz) of white crappie...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.