anyway to do this without post back to server

P

Paul

Hi I have a dropdown box with entries like

AY Activity Yellow
AB Activity Blue
AR Activity Red

This dropdown is followed by two text boxes and when the user selects AY I
would like to display the following in the text boxes

txbx1 [AY] txbx2 [Activity Yellow]
for AB Activity Blue
txbx1 [AB] txbx2 [Activity Blue]
So I am just spliting the string and displaying portions in each text box.
I was just wondering if there is a way to do this without posting back the
server on the dropdown SelectedIndexChanged event?
Thanks
 
B

bruce barker

yes, its simple javascript.

<script>
function doDropChange(e)
{
var txt1 = document.getElementById('<%=txt1.ClientID%>');
var txt2 = document.getElementById('<%=txt2.ClientID%>');
txt1.value = e.value.substr(0,2);
txt2.value = e.value.substr(3);
}
</script>

then in codebehind:

myDropDowm.Attributes["onchange"] = "doDropChange(this)";


-- bruce (sqlwork.com)
 
P

Paul

Thanks it works. For the code behind I used
if (!Page.IsPostBack)
{
this.dropdown.Attributes["onchange"] = "doDropChange(this)";
}
--
Paul G
Software engineer.


bruce barker said:
yes, its simple javascript.

<script>
function doDropChange(e)
{
var txt1 = document.getElementById('<%=txt1.ClientID%>');
var txt2 = document.getElementById('<%=txt2.ClientID%>');
txt1.value = e.value.substr(0,2);
txt2.value = e.value.substr(3);
}
</script>

then in codebehind:

myDropDowm.Attributes["onchange"] = "doDropChange(this)";


-- bruce (sqlwork.com)


Paul said:
Hi I have a dropdown box with entries like

AY Activity Yellow
AB Activity Blue
AR Activity Red

This dropdown is followed by two text boxes and when the user selects AY I
would like to display the following in the text boxes

txbx1 [AY] txbx2 [Activity Yellow]
for AB Activity Blue
txbx1 [AB] txbx2 [Activity Blue]
So I am just spliting the string and displaying portions in each text box.
I was just wondering if there is a way to do this without posting back the
server on the dropdown SelectedIndexChanged event?
Thanks
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top