a little help please...

G

Guest

hey all,

i apologize for this repost, but can someone please help me with writing
some javascript for my radiobuttonlist control.

all i want to do is when the radiobuttonlist control is clicked is to
populate a texbox on the same webform with the value that was selected.

thanks,
rodchar
 
C

cbDevelopment

Here is a potential solution:

Copy this function to your page code:

Function CreateRBLSelectorScript(ByVal r As RadioButtonList, _
ByVal t As TextBox) As String
Dim js As String
js = "var c=document.getElementsByTagName('INPUT');" _
& "for(var i=0;i<c.length;i++)" _
& "{if ((c.name=='" & r.UniqueID & "')&&(c.checked))" _
& "{document.getElementById('" & t.UniqueID & "').value= " _
& "c.value}}"
Return js
End Function

In your page_load sub add this line:

rbl.Attributes.Add("onclick", Me.CreateRBLSelectorScript(rbl, txt))

Replace all "rbl" references with the variable for your radiobuttonlist
and replace all "txt" references with the variable for the destination
textbox.

Testing performed:
- Browsers: IE 6, Opera 8.5, and Mozilla 1.04
- RadiobuttonList Table and Flow layouts
- Single and multiple RadioButtonLists on a page
- Two RadioButtonLists pointing to one textbox
- Two RadioButtonLists pointing to their own textboxes

Hope this resolves a long-outstanding issue for all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top