Internet Development

Moderators: None (Apply to moderate this forum)
Number of threads: 1024
Number of posts: 1892

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
2 Combo Box (PHP) Posted by ljuba on 25 Dec 2001 at 2:33 PM
Hi,

I have PHP+MySQL project. I have table for menu in MySQL database. There is field group and field subgroup. For item which has submenu field group is for example 3 and field subgroup is 0. All items for submenu has field group 3 and field subgroup is 1, 2, 3... Nothing special. I know how to make combobox using data from dataset to make combobox for groups, but I want to make 2 comboboxes where changing group in 1-st combobox will result changing data in 2-nd combobox where will be only items which are submenu for selected menu in 1-st combobox. It has to work without reload and I know it has to be done by JavaScript (generated by PHP). I think it could be solved by some arrays which I 'put' into combobox on event 'onChange', but can You help me with some example how to make this?

Thanks a lot

LJUBA<br>
Report
Re: 2 Combo Box (PHP) Posted by ljuba on 26 Dec 2001 at 5:13 AM
I found this. Thank You all.

LJUBA
Report
Re: 2 Combo Box (PHP) Posted by Manish on 27 Dec 2001 at 8:39 AM

Good.

You can post it here so others can benefit. :)

Thanks.


Manish
http://www.manishmalik.com

Report
Re: 2 Combo Box (PHP) Posted by ljuba on 27 Dec 2001 at 9:36 AM
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Combo Box-es</title>

<SCRIPT language=JavaScript1.1>
function reload() {
for(i=0;i<document.forms.length;i++)
{
document.forms[i].reset();
}
}
</SCRIPT>
<SCRIPT language=JavaScript1.1>
v=false;
if (typeof(Option)+"" != "undefined") v=true;
if(v){a=new Array(22);}

function getFormNum (formName) {
var formNum =-1;
for (i=0;i<document.forms.length;i++) {
tempForm = document.forms[i];
if (formName == tempForm) {
formNum = i;
break;
}
}
return formNum;
}

function provera(form) {
if (form.sel0.options[form.sel0.selectedIndex].value=="0") {
alert("You did not select any category");
return false;
}
if (form.sel1.options[form.sel1.selectedIndex].value=="0.0" || form.sel1.options[form.sel1.selectedIndex].value=="0") {
alert("You did not select any sub category");
return false;
}
form.submit();
return true;
}

function jmp(form, elt) { // The first parameter is a reference to the form.
if (form != null) {
with (form.elements[elt]) {
if (0 <= selectedIndex) location = options[selectedIndex].value;
}
}
}

var catsIndex = -1;
var itemsIndex;

if (v) { // Pocetak NS
function newCat(){
catsIndex++;
a[catsIndex] = new Array();
itemsIndex = 0;
}

function O(txt,url) {
a[catsIndex][itemsIndex]=new myOptions(txt,url);
itemsIndex++;
}

function myOptions(text,value) {
this.text = text;
this.value = value;
}

// Punjenje Niza ovde

newCat(); //--Select Category--

newCat(); //Group1
O("--Select Sub category--","0.0");
O("Subgroup11","Subgroup11");
O("Subgroup12","Subgroup12");
O("Subgroup13","Subgroup13");

newCat(); //Group2
O("--Select Sub category--","0.0");
O("Subgroup21","Subgroup21");
O("Subgroup22","Subgroup22");

newCat(); //Group3
O("--Select Sub category--","0.0");
O("Subgroup31","Subgroup31");

newCat(); //Group4
O("--Select Sub category--","0.0");
O("Subgroup41","Subgroup41");

newCat(); //Group5
O("--no sub category--","");

// Kraj punjenja niza

} // Kraj NS

function relate(formName,elementNum,j) {
if(v) {
var formNum = getFormNum(formName);
if (elementNum>=0) {
elementNum++; // reference next form, assume it follows in HTML
with (document.forms[formNum].elements[elementNum]) {
for(i=options.length-1;i>0;i--) options[i] = null; // null out in reverse order (bug workarnd)
for(i=0;i<a[j].length;i++) {
options[i] = new Option(a[j][i].text,a[j][i].value);
}
options[0].selected = true;
}
}
}
else {
jmp(formName,elementNum);
}
}

function IEsetup() {
if(!document.all) return;
IE5 = navigator.appVersion.indexOf("5.")!=-1;
if(!IE5) {
for (i=0;i<document.forms.length;i++) {
document.forms[i].reset();
}
}
}

window.onload = IEsetup;

//-->
</SCRIPT>
</head>

<body bgcolor="#64B1FF" link="#000000" vlink="#000000" alink="#FF6300" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" onload="javascript:reload()">

<form action="somescript.php" method="post" name=form1>

<table border="0" cellpadding="0" cellspacing="5" width="95%">
<tr>
<td width="55%">Write something: (optional)</td>
<td align="center" width="25%">
<div align="left"><input type="text" size="21" name="name"></div></td>
<td align="center" width="20%">&nbsp;</td>
</tr>
<tr>
<td width="55%" height="27">Choose Category:</td>
<td align="center" width="25%" height="27">
<div align="left">
<SELECT name=sel0 id=sel0 onchange=relate(form1,2,this.selectedIndex)>
<option value="0">Select Category</option>
<option value="GROUP 1">GROUP 1</option>
<option value="GROUP 2">GROUP 2</option>
<option value="GROUP 3">GROUP 3</option>
<option value="GROUP 4">GROUP 4</option>
<option value="GROUP 5">GROUP 5</option>
</SELECT>
</div></td>
<td align="center" width="20%" height="27">
<INPUT name=submit1 type=button value=Search onClick=provera(this.form)></td>
</tr>
<tr>
<td width="55%" height="16">Choose Sub Category: (Based on selected category)</td>
<td align="center" width="25%" height="16">
<div align="left">
<SELECT name=sel1 id=sel1>
<OPTION value="">Select SubCategory</OPTION>
</select>
</div></td>
<td align="center" width="20%" height="16">
<input id=brisi name=brisi type=reset value=Clear></td>
</tr>
<tr>
<td width="55%">Choose Sub-Sub Category: (optional)</td>
<td align="center" width="25%">
<div align="left">
<select name="location" size="1"> <option value="">----select town---</option>
<option value="Town 1">Town 1</option>
<option value="Town 2">Town 2</option>
<option value="Town 3">Town 3</option>
</select>
</div></td>
<td width="20%">&nbsp;</td>
</tr>
</table>
</form>

</body>
</html>

Report
Re: 2 Combo Box (PHP) Posted by Manish on 29 Dec 2001 at 12:00 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.