javascript for putting text in an asp.net edit control

M

Michelle Stone

I have a list box that I am populating (not via
databinding) from some tables from my SQL database. I
also have a TEXT BOX on the screen.

I want to display whatever the user clicks on the list
box on the edit box. I know I can do it by setting the
AUTOPOSTBACK property of the list box to TRUE and by
writing code to assign the .TEXT property of the edit box
to the selected item in the list box. But I want to avoid
the server round trip time.

Can someone give me the javascript equivalent statement?
I am new to javascript, so I would like to know the
complete statement as I should put it in my code-behind
(which is why i thought posting to this message to this
newsgroup rather than a javascript newsgroup).

Response.Write (something something something?)

Thanks...
 
E

Emilio

Hi,

Read up about using IsClientScriptRegistered and RegisterClientScript - You
will need to use these otherwise you will have to hardcode the javascript
into the page, and that can cause issues if you start using user controls
and the like.

- You will need to create a function for the Client-Side onclick event of
the listbox
- You will also need to add an attribute to the listbox so that it
recognises the OnClick event

Use lstBox.Attributes.Add("OnClick", "lstBoxClickfunction()")

the javascript functoin would look something like the following


function lstBoxClickfunction(){

i = document.getElementById("lstBox").selectedIndex

document.getElementById("txtBox").value =
document.getElementById("lstBox").options.value

}

email me if there are any issues
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top