Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Listbox Text to Javascript Pop-up Window URL

Is it possible to pass the contents of a textbox or Listbox into the URL portion of the javascript code window.open(URL)? I have an asp.net listbox control that displays URL values. When ever an end user clicks on another listbox, the URL listbox provides the specific URL. I am trying to pass this URL into the above javascript code, but I do not know the correct syntax to do this. This code will execute as an onclick event.

For clarification, similar to typing “+ ListBox.Text.ToString() +” or ‘” & List.Text & “’” to add the content of a listbox into something else, such as a textbox. Is there specific syntax to do the same, but add the listbox.text into javascript?

Thank you,

DFM


1 Answers

Simply add a client-side onclick handler to your listbox as shown below:

<asp:ListBox id="ListBox1" runat="server" .....
           onclick="openPopup(this)">
        ........
</asp:ListBox>

Then add the following javascript code:

<script type="text/javascript">
    function openPopup(e){
      window.open(e.value); 
    }
</script>
like image 138
Jose Basilio Avatar answered Feb 18 '26 17:02

Jose Basilio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!