Monday, March 26, 2012

pass text to javascript function

Hello,
I found this code and I want to pass this function a value
from a dataset.

How do I do this?

<INPUT onmouseover="func()" type="button" value="Button"
<script type=text/javascript>
function func()
{
//you could put anything here, e.g. opening a window etc.
alert('Hi');
}
</script<INPUT runat="server" id="myButton" onmouseover="func()" type="button"
value="Button"
In the code behind (C#):

myButton.Attributes["onmouseover"]=String.Format("func({0})", "my text");

Eliyahu

"prav" <prav@.hotmail.com> wrote in message
news:10ca01c4d624$ae4a5410$a501280a@.phx.gbl...
> Hello,
> I found this code and I want to pass this function a value
> from a dataset.
> How do I do this?
> <INPUT onmouseover="func()" type="button" value="Button">
>
> <script type=text/javascript>
> function func()
> {
> //you could put anything here, e.g. opening a window etc.
> alert('Hi');
> }
> </script>
Eliyahu Goldin wrote:
> <INPUT runat="server" id="myButton" onmouseover="func()"
> type="button" value="Button">
> In the code behind (C#):
> myButton.Attributes["onmouseover"]=String.Format("func({0})", "my
> text");
> Eliyahu

You might want to put quotes around that text:

String.Format("func('{0}')", "my text");

(and then you could still have problems with quotes inside the string)

Hans Kesting

0 comments:

Post a Comment