473,513 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1871
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
4355
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
5908
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
1676
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
2884
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
4905
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
1537
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
1869
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
6461
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
2162
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
2937
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
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7535
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
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.