Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

javascript combo box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rodchar - 27 Mar 2008 14:36 GMT
hey all,
how do you pass what is selected in a combo box as a parameter to a
javascript function call.

i know you can do this
onclick=test(this)

thanks,
rodchar
David R. Longnecker - 27 Mar 2008 15:52 GMT
rodchar-

Here's an example using an HTML SELECT and an .net DropDownList control.
The JavaScript is the same for both.  I'd recommend the onChange event,
not onClick, since onClick fires when the control itself is simply clicked
and onChange waits until you CHANGE the control (which, in this case, is
it's selected index value).

html:

   <form id="form1" runat="server">
   <div>
       <select id="SelectList" onchange="javascript:test(this)">
           <option value="Option 1">Option 1</option>
           <option value="Option 2">Option 2</option>
           <option value="Option 3">Option 3</option>
           <option value="Option 4">Option 4</option>
           <option value="Option 5">Option 5</option>
       </select>

       <asp:DropDownList runat="server" ID="SelectListControl" onchange="javascript:test(this)">
           <asp:ListItem Value="Option 1" Text="Option 1" />
           <asp:ListItem Value="Option 2" Text="Option 2" />
           <asp:ListItem Value="Option 3" Text="Option 3" />
           <asp:ListItem Value="Option 4" Text="Option 4" />
           <asp:ListItem Value="Option 5" Text="Option 5" />
       </asp:DropDownList>
       
       <div id="output"></div>
   </div>
   </form>

JavaScript:

<script type="text/javascript">
   function test(o)
   {
       var selectedValue = o.value;
       var output = document.getElementById('output');
       if (typeof output.textContent != 'undefined')
           output.textContent = selectedValue.toString(); // Firefox
       else
           output.innerText = selectedValue.toString(); // IE
       return true;
   }
</script>

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

> hey all,
> how do you pass what is selected in a combo box as a parameter to a
[quoted text clipped - 3 lines]
> thanks,
> rodchar
bruce barker - 27 Mar 2008 16:30 GMT
as the browser does not have a combobox,you are looking at an custom
control. you will need to review the docs (or source code) for the
control you pick.

if you mean the select (dropdown in asp.net) it simple

function test(e)
{
   alert(e.value);
}

-- bruce (sqlwork.com)

> hey all,
> how do you pass what is selected in a combo box as a parameter to a
[quoted text clipped - 5 lines]
> thanks,
> rodchar

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.