Forum Moderators: coopster
I suck with javascript and really just need some code that will post the category id back to the same script.
Heres some of my code:
<script type="text/javascript">
function sub()
{
need code here that sends category selection through POST back to same script.
}
</script>
<select name="category" onchange="sub()">
Any help with this would be great.
Thanks
use php to load the sub-cats into arrays in js and then jsut populate the second drop down by getting the selectedIndex value from the cat drop down and pushing the proper array into the sub cat drop down.
the other is to use your function to submit the form. If the action of the script is not self then you would have to use js to swap the action of the form and then submit it.
I don't know the code off the top of my head but a good DOM reference will help you find the proper form elements and methods.
function showDropDownBox(ddbox) {
if ( ddbox.options[ddbox.selectedIndex].value == "Option1" ) {
document.getElementById("option1").style.display = "inline";
} else {
document.getElementById("option1").style.display = "none";
}
if ( ddbox.options[ddbox.selectedIndex].value == "Option1" ) {
document.getElementById("spacer").style.display = "none";
} else {
document.getElementById("spacer").style.display = "inline";
}
</script>
Then the select field:
<select name="name" onchange="showDropDownBox(this)">
<option value="Option0" selected="selected">Option 0</option>
<option value="Option1">Option 1</option>
</select>
Then make 2 <div>'s that are the same height, 1 hidden and one inline. Now, When Option 1 is selected the div: <div id="option1" style="display: none;"> will show and the div: <div id="option1" style="display: inline;"> will hide and vice versa.
The reason for the 2 divs is so that the form height dosnt move up and down, you dont have to do it that way but i think it looks better.
Does that make sense?
this one ownes (I use it myself):
[yxscripts.com...]
hope this is ok, otherwise stripe the url like you mostly do moderators :)