Solved

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

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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.
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 …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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)

705 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