The Arcive of vBulletin Modifications Site. |
|
|
#1
|
|||
|
|||
|
Hi,
Im trying to make a form....but I think I need a javascript to get it the way i want it. I have this html code: HTML Code:
<select name="ltype"> <option selected>Choose type</option> <option value="maindir">Main menu - direct link</option> <option value="subdir">Sub menu - direct link</option> </select> Thanks in advance! |
|
#2
|
||||
|
||||
|
You need to use JS to toggle the 'display' CSS property of the form parts. When a page element has its display set to 'none', then it is removed from view. So you need to attach an 'onchange' event to the select box, and show/hide parts of the form depending on what is selected.
Here's an example: Code:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function showpartChanged(obj)
{
// Go through the options to hide/show
// each section
for(i = 0; i < obj.options.length; i++)
{
// Ge the value (ie: part1)
val = obj.options[i].value;
// Create the id of the form parts (ie: form_part1)
form_part = 'form_' + val;
// If its selected, then show the form part
if(obj.options[i].selected)
document.getElementById(form_part).style.display = '';
// It should be hidden
else
document.getElementById(form_part).style.display = 'none';
}
}
</script>
</head>
<body>
<select id="showpart" onchange="showpartChanged(this)">
<option value="part1" selected="selected">Part 1</option>
<option value="part2">Part 2</option>
<option value="part3">Part 3</option>
</select>
<div id="form_part1">
Form Part 1
</div>
<div id="form_part2" style="display:none;">
Form Part 2
</div>
<div id="form_part3" style="display:none;">
Form Part 3
</div>
</body>
</html>
|
|
#3
|
|||
|
|||
|
By default, I dont want any of the options to show up, how can i achieve that?
Thank you so much for taking the time to help me! |
|
#4
|
||||
|
||||
|
Just stick style="display:none" in the tag to hide it.
|
|
#5
|
|||
|
|||
|
great, thanks!
just one more thing....i want to add <option selected>something here</option> but when i do that (and yes i have removed selected="selected" from form_part1) everything stops working. I mean, the parts wont show up. Thanks in advance! |
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|