anyway to do this without post back to server

  • Thread starter Thread starter Paul
  • Start date Start date
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
 
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)
 
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
 
Back
Top