Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Wednesday, March 21, 2012

Populate textbox with dropdown selection (in Wizard Control), using javascript

I have a Wizard Control that contains a number of controls:

After the user selects an item from a DropDown, and the control has lostfocus, I need the selected value to pre-populate a TextBox usingjavascript.

If I create a 'new website' and just throw a dropdown list and textbox onto the page the following code works perfectly:

** Default.aspx.vb:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.Attributes.Add("onblur", "FillTextbox()")
End Sub

** Default.aspx:

function FillTextbox ()
{
document.getElementById("TextBox1").value=document.getElementById("DropDownList1").value;
}

The above code, however DOESN'T work if the controls are embedded in a wizard control.

Thus, my question is: How do I get the code to work if the DropDown and TextBox controls are in a Wizard Control?

Any help would be much appreciated!

I believe when the control is embedded within another control the actual name that ends up being used includes the parent-control's name, e.g. Parent_mycontrol. Take a look at the source (right click, View Source) when you run the page to find the actual name of the control. You can reference it by that name in your javascript, fillTextbox() function.

Good luck.


You need to find the correct ID for the TextBox control. As suggested by the fellow developer you need to use the View Source and find the correct ID for the TextBox control. Once, you find the correct ID simply use that Id in the javascript function.

Thank you both SO MUCH for your help! That worked like a charm!Big Smile

Populate Textboxes?

I am trying to populate a textbox with a random number and for the life of me I cant get the textbox to populate... any help?

Sub Page_Load()

Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)

textbox1.text = iNum

end sub

I run the page and the textbox is still blank.Is the textbox standalone in the page, or is it nested in a formview?

Can you put anything in the textbox, i.e. textbox.text = "something"
no its not letting me put textbox1.text ="anything" ... I do have it between Form tags...

Im lost
Is it supposed to populate on page load? If so do you have te call inside an if not isportback...
yea I would like for it to populate on the page load
In that case, on the page load sub, add the following:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
'Put all your page load stuff in here including the textbox piece
Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)

textbox1.text = iNum

End If

End Sub
bah Im an idiot... lol... thanks...

Anjari