Solved

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

Posted on 2014-04-01
4
568 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell script + checking for a process and determining cpu or memory 16 96
Debugging Html 8 31
Use Mid in Html 6 21
Link Anchor Not working 9 46
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.

763 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