pass text to javascript function

P

prav

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>
 
E

Eliyahu Goldin

<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
 
H

Hans Kesting

Eliyahu said:
<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
 

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

Top