Change Textbox text on Rollover

  • Thread starter Thread starter KCRichards59@hotmail
  • Start date Start date
K

KCRichards59@hotmail

I'm trying to change the text in a textbox when I roll over a hyperlink on
the page.

I know to use the
"this.MyHyperlink.Attributes.Add("onMouseOver", "ChangeText()");"

but I'm not sure if I'm doing it correctly and I'm not sure how to set up
the Javascript in the ASP page.

I have 4 different hyperlinks and I wanted to perhaps set it up as a case
statement.

Any help would be greatly appreciated.

Karl Richards
 
You could do something like this:
Client Side Code:
<script language="javascript" type="text/javascript">
function ChangeText(oElement, string)
{
oElement.innerText = string;
}
</script>
Server Side Code:
private string _hlinkText1;
private string _hlinkText2;
private string _hlinkText3;
private string _hlinkText4;

protected void Page_Load(object sender, EventArgs e)
{
_hlinkText1 = "1";
_hlinkText2 = "2";
_hlinkText3 = "3";
_hlinkText4 = "4";

HyperLink1.Attributes.Add("onMouseOver", "ChangeText(" +
TextBox1.ClientID + ',' + _hlinkText1 + ")");
HyperLink2.Attributes.Add("onMouseOver", "ChangeText(" +
TextBox1.ClientID + ',' + _hlinkText2 + ")");
HyperLink3.Attributes.Add("onMouseOver", "ChangeText(" +
TextBox1.ClientID + ',' + _hlinkText3 + ")");
HyperLink4.Attributes.Add("onMouseOver", "ChangeText(" +
TextBox1.ClientID + ',' + _hlinkText4 + ")");
}

If you have the remote possibility of turning this into a user control I
would pass the client id.
I hope I understood your question correctly and helped :)

Regards,
Brian K. Williams
 
Sorry I forgot about your switch statement

Client Side Script:
function ChangeText(oElement, param)
{
switch (param)
{
case 1:
oElement.innerText = "Some Text1";
break;
case 2:
oElement.innerText = "Some Text2";
break;
case 3:
oElement.innerText = "Some Text3";
break;
case 4:
oElement.innerText = "Some Text4";
break;
}
}

Regards,
Brian K. Williams
 
Sorry again, I'm a mess today.

I wouldn't use the switch statement unless the text was small. Remember the
client will download all the text in the JavaScript so large chunks of text
will affect performance. However, you can cache it by including it with
src=YourJavaScriptFile

Regards,
Brian K. Williams
 
Back
Top