Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:41:29+00:00 2026-06-08T19:41:29+00:00

I am currently trying to update a textbox using an ‘onclick’ event inside a

  • 0

I am currently trying to update a textbox using an ‘onclick’ event inside a listbox.

Basically, when setting the ‘onclick’ event attribute, I need to pass the selected listbox value. However, the issue that is happening is when everything is being built for the very first time, there is no selected value, so it tries to pass a null and errors out.

Some code…

//listbox attribute creation...
Me.listbox.Attributes("onclick") = "javascript:board_click_button('" & Me.listbox.SelectedItem.Text & "');"

If I set the SelectedValue to a specific index then every time the user clicks, regardless of what they select, the hardcoded index value is what is always returned.

Is there a way to get ‘onclick’ to do what I need it it? I didn’t post any further code since I didn’t think it would help, but I can if its needed. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:41:31+00:00Added an answer on June 8, 2026 at 7:41 pm

    You need to understand the difference between server-side and client-side.

    Server-side is everything that happens on the server (e.g. ASP, ASP.NET, PHP) that is used to create the HTML that is sent to the browser. It also deals with the information that is returned by the browser when the user submits stuff back (the post-back).

    Client-side is everything that happens on the browser once the HTML has been received, or when user does something on the page like clicking an element.

    This code is being created on the server, therefore as far as the browser is concerned, the text parameter is never going to change (split over lines for visibility)…

    Me.listbox.Attributes("onclick") = "javascript:board_click_button('" 
                                       & Me.listbox.SelectedItem.Text & "');"
    

    The browser will receive something like (simplified for visibility)…

    <select onclick="javascript:board_click_button('hello world');" ...
    

    Instead, what I think you want is this…

    Me.listbox.Attributes("onclick") = "board_click_button(this.options[this.selectedIndex].text);"
    

    What this will do is allow the javascript to use the this variable (which is the object that has caused the event, in this case the <select>) to find the currently selected item text.

    (Also, please note you do not need to put javascript: at the start of onclick type events – the browser already knows it’s javascript. You only need to put it if you use javascript within the href of an <a> tag.)

    UPDATE

    Here is a very quick test that works correctly for me (displaying in an alert box, the text from the item that has been selected)…

    <asp:ListBox runat="server" onclick="alert(this.options[this.selectedIndex].text);">
      <asp:ListItem Value="1">one</asp:ListItem>
      <asp:ListItem Value="2">two</asp:ListItem>
      <asp:ListItem Value="3">three</asp:ListItem>
    </asp:ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to update a row using the sqlitedatabase.update method here: Heres the
I'm currently trying to retrieve the coordinates of the cursor using function getCursor(event) {
Im currently trying to downlaod a audio track from a WCF, i need some
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
Trying to access a RequiredFieldValidator control that's inside a GridView in the RowCommand event
I am currently trying to figure out how to update documents in MongoDb via
I'm currently trying to update my in house search engine to use multiple words.
I am currently trying to update a chart which is on my form to
We are currently trying to implement a SELECT FOR UPDATE in order to lock
I'm trying to update the text in a textbox when a value is selected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.