Solved

Help with Populating a text box based on a selction from a drop down. (Java Script)

Posted on 2014-04-01
4
569 Views
Last Modified: 2014-04-06
Experts,

Could you please help me with the following and an example or a sample code would be really helpful.

1. I have a drop down with three options (say option1, option2, option3) and when option1 selected, I need to populate a text box.
2. If the option1 is selected and if the user changes to other two options then text should be hidden or not visible to the user
3. Nothing should happen when option2 and options3 are selected.

Thanks in advance and appreciate all your help.
0
Comment
Question by:Tpaul_10
[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
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39971367
Using jQuery..

<script>
function select1Changed() {
            if ($('#select1').val() == "one") {
                $('#textbox1').val('some value');
                $('#textbox1').show();
            } else {
                $('#textbox1').hide();
            }
        }
</script>

<select id="select1" onchange="select1Changed();">
            <option value="one">Option1</option>
            <option value="two">Option2</option>
            <option value="three">Option3</option>
        </select>
        <br />
        <input type="text" id="textbox1" value=""/>
0
 

Author Comment

by:Tpaul_10
ID: 39973219
Thanks for the reply, appreciate it.
But I would like to generate just the text box with no value like

Enter the Other info : TEXTBOX...

Hope that is clear and would like to have it in JavaScript instead of JQuery...

Appreciate your help
0
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 500 total points
ID: 39974152
function select1Changed() {
            var ddnSelect = document.getElementById("select1");
            var ddnSelectedValue = ddnSelect.options[ddnSelect.selectedIndex].value;
            if (ddnSelectedValue == "one") {
                document.getElementById("divOtherOption").style.display = 'block';
            } else {
                document.getElementById("divOtherOption").style.display = 'none';
            }
        }

<select id="select1" onchange="select1Changed();">
            <option value="one">Option1</option>
            <option value="two">Option2</option>
            <option value="three">Option3</option>
        </select>
        <br />
        <div id="divOtherOption">
        Enter the Other info : <input type="text" id="textbox1" value=""/>
        </div>
0
 

Author Closing Comment

by:Tpaul_10
ID: 39982119
Thank You
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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