Showing posts with label type. Show all posts
Showing posts with label type. Show all posts

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

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

Pass value to second DropDownList from the first one

I want pass value to 2nd DropDownList from 1st one. I use "DropDownList1.SelectedValue", but got error message." can't transfer data type from varchar,..." Yes, in Database, it is varchar type.

Here is a source code:

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string sql = "select Address from myTable where Name=" + DropDownList1.SelectedValue ;
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "myTable");
DataView dv=ds.Tables [0].DefaultView ;

DropDownList2.DataTextField="Address";
DropDownList2.DataValueField ="Address";
//DropDownList2.DataSource =ds.Tables[0].DefaultView;
DropDownList2.DataSource=dv;
DropDownList2.DataBind ();

con.Close();
}

Two things.

1) I would use a SqlDataReader to populate the DropDownList. It is 100x faster than a DataSet.

2) Try DropDownList1.SelectedItem.Value to get the value of the DropDownList


move your datasource code line above both your datatextfield and datavaluefield

[edit]

He is right about the speed--much faster.


I did try: DropDownList1.SelectedItem.Value, but got same error msg.

You are missing the single quotes around the parameter, try:

string sql = "select Address from myTable where Name='" + DropDownList1.SelectedValue + "'" ;


Better NOW.