[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JavaScript/jQuery: Open Select Options upon Trigger

Posted on 2013-05-23
3
Medium Priority
?
1,318 Views
Last Modified: 2013-06-03
Is it possible to open the select options with jQuery?

This does NOT work:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

 $('#openSSS').click(function(){
  $('#sss').click();
 });

});

</script>
</head>
<body>

<select name="Choose_One" id="sss"> 
<option value="a">Option 1</option> 
<option value="b">Option 2</option> 
<option value="c">Option 3</option> 
<option value="d">Option 4</option> 
<option value="e">Option 5</option> 
</select> 

<input type="button" value="Click to open the select" id="openSSS" />

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39191296
Why not? You have make just a small mistake see

<script type="text/javascript">
$(document).ready(function(){

 $('#openSSS').click(function(){
  var selval=$('#sss').val();
  alert(selval);
 });

});

</script>

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 39191513
That solution is useless.  I want the options to slide down when you click on the button.  I do not need an alert!
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 2000 total points
ID: 39191525
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

872 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