?
Solved

dynamic form elemnts for select option

Posted on 2003-02-25
3
Medium Priority
?
184 Views
Last Modified: 2011-10-03
Hi Guys,

i turn to u as my last hope.

i have a requirement as follows.i need a javascript that will dynamically populate form elements like text box,drop down box,ete based on select option.

i dont mind even if these form elements are hidden and become activated onChange of select box.

for ex:
<select name="leavetype">
<option value="A">Maternity Leave</option>
<option value="B">Compensatory Leave</option>
<option value="C">Bevearment Leave</option>
</select>

now when i select option A, an input type =text must be populated in the html page.
when i select B, a drop down box must be popultaed.

i hope u get the idea.pl pl pl pl do help.hope this will work in both browsers ie and ns.

thanks in advance ;
guru
0
Comment
Question by:guruaxy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
hexagon47 earned 200 total points
ID: 8018055
<html>
<head>

<script type="text/javascript">

function showInput()
{
document.getElementById('relOption1').style.display = 'block';
document.getElementById('inputOpt1').value = 'whatever';
}
function showSelect()
{
document.getElementById('relOption1').style.display = 'none';
document.getElementById('relOption2').style.display = 'block';
document.getElementById('relOption3').style.display = 'none';
}
function showText()
{
document.getElementById('relOption1').style.display = 'none';
document.getElementById('relOption2').style.display = 'none';
document.getElementById('relOption3').style.display = 'block';
}

function decide()
{
if(myForm.mySelect.options[1].selected)
{
showInput();
}
if(myForm.mySelect.options[2].selected)
{
showSelect();
}
if(myForm.mySelect.options[3].selected)
{
showText();
}
}</script>
</head>
<body>

<form action="" name="myForm">

<select name="mySelect" onchange="decide()">
     <option>please select</option>
     <option>show input box</option>
     <option>show select</option>
     <option>show text</option>
</select>

<div id="relOption1" style="display:none">
<input type="text" value="" id="inputOpt1" />
</div>
</form>

<div id="relOption2" style="display:none">
<select name="mySubSelect">
     <option>option1</option>
     <option>option2</option>
     <option>option3</option>
</select>
</div>

<div id="relOption3" style="display:none">
just text
</div>

</form>

</body>
</html>

i hope this helps you
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10083562
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area:
RECOMMENDATION:

 - [Points to hexagon47 Grade B]

Please leave any comments here within the next seven days.
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************

jAy
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question