Page 1 of 1

I have a problems about a dynamic menu

Posted: Mon Oct 25, 2004 7:14 am
by patrik
Sami | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

I have like a menu, which it has a two menu: category and subcategory.
When I click a menu -category, open a subcategory about of this category:
example:
3 categories: cars, boats, truck...
subcategory:  cars -> BMW, Renault, Ford, Seat...
                    boats ->Pershing, Marines....
                    truck ->Volvo, Marcedes, Scania ....

These I have like in a php form, when I add this....category, subcategory ...etc

I have an example , but it have errors...help me... or other example

Code: Select all

<script Language="JavaScript"> 

Povezave=new Array(1); 
Povezave[0]=new Array(0); 
Povezave[1]=new Array(3); 
Povezave[2]=new Array(4); 

Povezave[0][0]=""; 

//Gospodinjski aparati; 
Povezave[1][0]=""; 
Povezave[1][1]="Seat"; 
Povezave[1][2]="BMW"; 
Povezave[1][3]="Renault"; 

//Bela tehnika; 
Povezave[2][0]=""; 
Povezave[2][1]="Pershing"; 
Povezave[2][2]="Marines"; 
Povezave[2][3]="xxxx"; 
Povezave[2][4]="yyyyy"; 

function BuildPovezave(num) 
{ 
document.admin.model.selectedIndex=0; 
for(ctr=0;ctr<Povezave[num].length;ctr++) 
{ 
document.admin.model.options[ctr]=new Option(Povezave[num][ctr],Povezave[num][ctr]); 
} 
document.admin.model.length=Povezave[num].length; 
} 
function BuildPovezave2(num) 
{ 
document.admin.model.selectedIndex=0; 
for(ctr=0;ctr<Povezave[num].length;ctr++) 
{ 
document.admin.model2.options[ctr]=new Option(Povezave[num][ctr],Povezave[num][ctr]); 
} 
document.admin.model2.length=Povezave[num].length; 
} 

</script> 

<?php

form....
print "<tr><td width="25%"><div align="right"><font size="1">kategorija:</font></div></td></tr>"; 
print "<tr><td width="75%"><select name="znamka" size="1" class="form_field" id="znamka" style="width: 170px" onChange="BuildPovezave(this.selectedIndex);">"; 
          
print "<option selected value="0">vsi tipi</option>"; 
print "<option Value=Cars>Cars</option>"; 
print "<option Value=Boats>Boats</option>"; 
print "</SELECT> "; 
print "</td></tr>"; 
          
print "<tr><td width="25%"><div align="right"><font size="1">podkategorija:</font></div></td></tr>"; 

print "<tr><td width="75%"><select name="model" size="1" class="form_field" id="select" style="width: 170px">"; 

print "<option value="0">vsi modeli</option>"; 
print "</SELECT> "; 
print "</td></tr>"; 



?>

Re: I have a problems about a dynamic menu

Posted: Mon Oct 25, 2004 12:10 pm
by scorphus
Hello, welcome to DevNetwork.
patrik wrote:(...) I have an example , but it have errors...help me... or other example :) (...)
Then please, post those error messages.

-- Scorphus

Posted: Mon Oct 25, 2004 12:40 pm
by kettle_drum
Error on about line 46? Also you dont need to keep using a print function on each line:

Code: Select all

echo "
text
on multiple
lines
";

Error on about line 46?

Posted: Tue Oct 26, 2004 1:25 am
by patrik
is true?
i don' t have error, but it's not work this code....
I see category, when I click a category, I don't see a subcategory....
what's wrong?

thanks!
:)

Posted: Tue Oct 26, 2004 11:42 am
by scorphus
Humm, it seems to be a problem with JavaScript rather than with PHP. Tell us if you get any error message in the JavaScript console. JavaScript console is a Mozilla/Mozilla Firefox feature, if you don't know, and it is a very interesting developer tool ( http://www.mozilla.org/products/firefox/ ). Is there a way we can see the whole page? Or maybe, can we access it online?

dynamic menu

Posted: Wed Oct 27, 2004 5:28 am
by patrik
I have done this...

does anyone the code to make dynamic options list so that the second option (select list) is generated by the selection of the first option select list

say the 1st option list was the type of sport; NFL, NBA and NHL
Code:
<select name="sport_type">
<option value="NFL">NFL
<option value="NBA">NBA
<option value="NHL">NHL
</select>



so if somone select NBA the second list would get generated and be:
Code:
<select name="NBA">
<option value="Atlanta">Atlanta
<option value="Boston">Boston
etc
</select>

I find an example....

Posted: Wed Oct 27, 2004 5:32 am
by patrik
but I have in php code....not html....when I used in form (PHP)...where the values -data write in MySQL


code;:
<html>
<head>
<title>Dynamic List Box</title>
<script type="text/javascript">
<!--
var NBA = new Array("Atlanta", "Boston", "Chicago")
var NHL = new Array("Buffalo","Montreal","Edmonton")
var NFL = new Array("Denver","Baltimore","Indianapolis")

function loadList(which) {
var theList = eval(which);
document.theForm.team.options.length = theList.length;
for (i=0; i<theList.length; i++) {
document.theForm.team.options = new Option(theList, theList);
}
}
function resetLists() {
loadList("NBA");
document.theForm.league.options[0].selected = true;
}
window.onload = resetLists;
// -->
</script>
</head>
<body>

<form name="theForm" method="post" action="echo_post.php">
<select name="league" onchange="loadList(this.options[this.selectedIndex].value)" size="1">
<option value="NBA">NBA</option>
<option value="NHL">NHL</option>
<option value="NFL">NFL</option>
</select>

<select name="team" size="1"></select>

<input type="submit"><input type="reset" onclick="resetLists()" />
</form>
</body>
</html>


how I write this in PHP code???
thanks....

e-mail:
paprikb@yahoo.com

Posted: Wed Oct 27, 2004 6:14 am
by CoderGoblin
scorphus wrote:Humm, it seems to be a problem with JavaScript rather than with PHP. Tell us if you get any error message in the JavaScript console. JavaScript console is a Mozilla/Mozilla Firefox feature, if you don't know, and it is a very interesting developer tool ( http://www.mozilla.org/products/firefox/ ). Is there a way we can see the whole page? Or maybe, can we access it online?
For Internet Explorer Javascript Errors you could use this Microsoft debugger...
http://www.microsoft.com/downloads/deta ... laylang=en

To debug javascript I normally use the Firefox Javascript console, then run the on IE with the debugger installed to find out the glitches there.

Re: I find an example....

Posted: Wed Oct 27, 2004 1:43 pm
by scorphus
patrik wrote:(...) how I write this in PHP code??? (...)
You can't do it exactally this way in PHP. If you have to do it in PHP it will not be "dynamic". You will have to submit the entire form each time the user change the league, then redraw the form with the league's teams.

-- Scorphus