Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now