[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2014-04-01
4
Medium Priority
?
578 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

656 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