...

View Full Version : Categories & subcategories & more subcategories!?



ivan85
01-11-2004, 03:11 PM
Hi i don't know anything about JavaSctipt, but i need one little script for form. I need something like that script in attachment only whit 3 "select meny".

For example in first i choose country, then i get in second the list of states in the country, and when i choose state in third i get list of cities whit in the state.

Can anyone write this for me?

Please help me.

Thank You!

JAVAEOC
01-11-2004, 04:02 PM
only works in NS... sorry could fix it :(

Garadon
01-11-2004, 04:55 PM
this migth help get an idea of how to do it.


<head>
<script language="JavaScript1.2">
var i=0;
var tc=new Array();

tc[i++]=new Array('USA',new Array('SC','Washington','New York'),new Array('NC','Baltimore','Orleans'));
tc[i++]=new Array('Europe',new Array('Germany','Berlin'));
function fillCategory()
{
for (loop =document.getElementById('Category').options.length-1; loop > -1; loop--)
{
document.getElementById('Category').options[loop] = null;
}

for (loop = 1; loop < tc[document.getElementById('Type').selectedIndex].length; loop++)
{
document.getElementById('Category').options[loop-1] = new Option(tc[document.getElementById('Type').selectedIndex][loop][0]);
}
fillSubCategory();
}

function fillSubCategory()
{

for (loop =document.getElementById('Subcategory').options.length-1; loop > -1; loop--)
{
document.getElementById('Subcategory').options[loop] = null;
}

if(tc[document.getElementById('Type').selectedIndex][document.getElementById('Category').selectedIndex+1].length>1)
{
for (loop = 1; loop < tc[document.getElementById('Type').selectedIndex][document.getElementById('Category').selectedIndex+1].length; loop++)
{
document.getElementById('Subcategory').options[loop-1] = new Option(tc[document.getElementById('Type').selectedIndex][document.getElementById('Category').selectedIndex+1][loop]);
}
}
}
</script>
</head>
<form name="form1" method="post" action="">
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Step 1</td>
<td>
<select name="Type" id="Type" onchange="fillCategory();">
<script language="JavaScript1.2">
var i=0;
for(i=0;i<tc.length;i++)
{
document.write('<option value='+i+'>'+tc[i][0]+'</option>')
}
</script>
</select>
</td>
</tr>
<tr>
<td>Step 2</td>
<td>
<select name="Category" id="Category" onchange="fillSubCategory();">
<script language="JavaScript1.2">
var i=0;
for(i=1;i<tc[0].length;i++)
{
document.write('<option value='+i+'>'+tc[0][i][0]+'</option>')
}
</script>
</select>
</td>
</tr>
<tr>
<td>Step 3</td>
<td>
<select name="Subcategory" id="Subcategory">
<script language="JavaScript1.2">
var i=0;
for(i=1;i<tc[0][1].length;i++)
{
document.write('<option value='+i+'>'+tc[0][1][i]+'</option>')
}
</script>
</select>
</td>
</tr>
</table>
</form>

ivan85
01-11-2004, 05:23 PM
Thank you all!

I think that will do the job!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum