By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

Javascript not working

P: n/a
I have the following code that attaches a Javascript confirm box to my
checkbox. When I select the checkbox, the window comes up fine, but it
never executes the XfertoDefault_Click function when I press the Yes button.
If I take off the Javascript event, the checkbox works fine.

XferToDefault.Attributes.Add("onclick", "return confirm('Are you sure you
want copy these entries?');")

<asp:CheckBox ID="XferToDefault" AutoPostBack="true"
OnCheckedChanged="XferToDefault_Click" runat="server"/>

If I change the checkbox to an ImageButton, it all works fine - the
Javascript window as well as going to the function after the Yes button is
pressed.
<asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
ImageUrl="../../buttons/xfer.gif" runat="server"/>

Why doesn't the checkbox (or radiobutton) work?

Thanks,

Tom
Nov 19 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Tom,

Try

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want
copy these entries?')return;")

If it works, I can explain the reason.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have the following code that attaches a Javascript confirm box to my
checkbox. When I select the checkbox, the window comes up fine, but it
never executes the XfertoDefault_Click function when I press the Yes button. If I take off the Javascript event, the checkbox works fine.

XferToDefault.Attributes.Add("onclick", "return confirm('Are you sure you
want copy these entries?');")

<asp:CheckBox ID="XferToDefault" AutoPostBack="true"
OnCheckedChanged="XferToDefault_Click" runat="server"/>

If I change the checkbox to an ImageButton, it all works fine - the
Javascript window as well as going to the function after the Yes button is
pressed.
<asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
ImageUrl="../../buttons/xfer.gif" runat="server"/>

Why doesn't the checkbox (or radiobutton) work?

Thanks,

Tom

Nov 19 '05 #2

P: n/a
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
Tom,

Try

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want copy these entries?')return;")
I tried that, but there must be a problem with the Javascript. I don't get
the confirm box at all now, as well as not going to the function.

Tom

If it works, I can explain the reason.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have the following code that attaches a Javascript confirm box to my
checkbox. When I select the checkbox, the window comes up fine, but it
never executes the XfertoDefault_Click function when I press the Yes

button.
If I take off the Javascript event, the checkbox works fine.

XferToDefault.Attributes.Add("onclick", "return confirm('Are you sure you want copy these entries?');")

<asp:CheckBox ID="XferToDefault" AutoPostBack="true"
OnCheckedChanged="XferToDefault_Click" runat="server"/>

If I change the checkbox to an ImageButton, it all works fine - the
Javascript window as well as going to the function after the Yes button is pressed.
<asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
ImageUrl="../../buttons/xfer.gif" runat="server"/>

Why doesn't the checkbox (or radiobutton) work?

Thanks,

Tom


Nov 19 '05 #3

P: n/a
One more bracket:

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want
copy these entries?'))return;")
--
Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
Tom,

Try

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want
copy these entries?')return;")


I tried that, but there must be a problem with the Javascript. I don't

get the confirm box at all now, as well as not going to the function.

Tom

If it works, I can explain the reason.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have the following code that attaches a Javascript confirm box to my
checkbox. When I select the checkbox, the window comes up fine, but it never executes the XfertoDefault_Click function when I press the Yes button.
If I take off the Javascript event, the checkbox works fine.

XferToDefault.Attributes.Add("onclick", "return confirm('Are you sure you want copy these entries?');")

<asp:CheckBox ID="XferToDefault" AutoPostBack="true"
OnCheckedChanged="XferToDefault_Click" runat="server"/>

If I change the checkbox to an ImageButton, it all works fine - the
Javascript window as well as going to the function after the Yes
button is pressed.
<asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
ImageUrl="../../buttons/xfer.gif" runat="server"/>

Why doesn't the checkbox (or radiobutton) work?

Thanks,

Tom



Nov 19 '05 #4

P: n/a
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eG**************@TK2MSFTNGP15.phx.gbl...
One more bracket:

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want copy these entries?'))return;")
That works fine now,

How come?

Why didn't the other one work if it worked with the asp:imageButton and
asp:linkbutton?

Thanks,

Tom

--
Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
Tom,

Try

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you
want
copy these entries?')return;")


I tried that, but there must be a problem with the Javascript. I don't

get
the confirm box at all now, as well as not going to the function.

Tom

If it works, I can explain the reason.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> I have the following code that attaches a Javascript confirm box to
my > checkbox. When I select the checkbox, the window comes up fine, but it > never executes the XfertoDefault_Click function when I press the Yes
button.
> If I take off the Javascript event, the checkbox works fine.
>
> XferToDefault.Attributes.Add("onclick", "return confirm('Are you

sure you
> want copy these entries?');")
>
> <asp:CheckBox ID="XferToDefault" AutoPostBack="true"
> OnCheckedChanged="XferToDefault_Click" runat="server"/>
>
> If I change the checkbox to an ImageButton, it all works fine - the
> Javascript window as well as going to the function after the Yes

button
is
> pressed.
> <asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
> ImageUrl="../../buttons/xfer.gif" runat="server"/>
>
> Why doesn't the checkbox (or radiobutton) work?
>
> Thanks,
>
> Tom
>
>



Nov 19 '05 #5

P: n/a
Tom,

If an input html control, such as a regular button, or a checkbox, has both
client- and server-side onclick event assigned, asp.net arranges it in the
way

onclick="<javascript for client-side>; <javascript to invoke server-side
handler>;"

In your case you had

onclick="return confirm(...); <javascript to invoke server-side handler>;"

Obviously, the javascript to invoke server-side handler never had its chance
to run.

For ImageButton, which renders as <input type=image>, asp.net apparently
arranges event handlers differently.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:uv**************@TK2MSFTNGP14.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eG**************@TK2MSFTNGP15.phx.gbl...
One more bracket:

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want
copy these entries?'))return;")


That works fine now,

How come?

Why didn't the other one work if it worked with the asp:imageButton and
asp:linkbutton?

Thanks,

Tom


--
Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
> Tom,
>
> Try
>
> XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure you want
> copy these entries?')return;")

I tried that, but there must be a problem with the Javascript. I don't
get
the confirm box at all now, as well as not going to the function.

Tom

>
> If it works, I can explain the reason.
>
> Eliyahu
>
> "tshad" <tf*@dslextreme.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
> > I have the following code that attaches a Javascript confirm box
to my > > checkbox. When I select the checkbox, the window comes up fine,
but
it
> > never executes the XfertoDefault_Click function when I press the

Yes > button.
> > If I take off the Javascript event, the checkbox works fine.
> >
> > XferToDefault.Attributes.Add("onclick", "return confirm('Are you

sure you
> > want copy these entries?');")
> >
> > <asp:CheckBox ID="XferToDefault" AutoPostBack="true"
> > OnCheckedChanged="XferToDefault_Click" runat="server"/>
> >
> > If I change the checkbox to an ImageButton, it all works fine - the > > Javascript window as well as going to the function after the Yes

button
is
> > pressed.
> > <asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
> > ImageUrl="../../buttons/xfer.gif" runat="server"/>
> >
> > Why doesn't the checkbox (or radiobutton) work?
> >
> > Thanks,
> >
> > Tom
> >
> >
>
>



Nov 19 '05 #6

P: n/a
Eliyahu Goldin wrote:
Tom,

If an input html control, such as a regular button, or a checkbox,
has both client- and server-side onclick event assigned, asp.net
arranges it in the way

onclick="<javascript for client-side>; <javascript to invoke
server-side handler>;"

... apart from the ";" inbetween, you have to add that yourself to your (client-side) code!
In your case you had

onclick="return confirm(...); <javascript to invoke server-side
handler>;"

Obviously, the javascript to invoke server-side handler never had its
chance to run.

For ImageButton, which renders as <input type=image>, asp.net
apparently arranges event handlers differently.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:uv**************@TK2MSFTNGP14.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eG**************@TK2MSFTNGP15.phx.gbl...
One more bracket:

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure
you want copy these entries?'))return;")


That works fine now,

How come?

Why didn't the other one work if it worked with the asp:imageButton
and asp:linkbutton?

Thanks,

Tom


--
Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
> Tom,
>
> Try
>
> XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you
> sure you want copy these entries?')return;")

I tried that, but there must be a problem with the Javascript. I
don't get the confirm box at all now, as well as not going to the
function.

Tom

>
> If it works, I can explain the reason.
>
> Eliyahu
>
> "tshad" <tf*@dslextreme.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
>> I have the following code that attaches a Javascript confirm box
>> to my checkbox. When I select the checkbox, the window comes up
>> fine, but it never executes the XfertoDefault_Click function
>> when I press the Yes button. If I take off the Javascript event,
>> the checkbox works fine.
>>
>> XferToDefault.Attributes.Add("onclick", "return confirm('Are you
>> sure you want copy these entries?');")
>>
>> <asp:CheckBox ID="XferToDefault" AutoPostBack="true"
>> OnCheckedChanged="XferToDefault_Click" runat="server"/>
>>
>> If I change the checkbox to an ImageButton, it all works fine -
>> the Javascript window as well as going to the function after the
>> Yes button is pressed.
>> <asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
>> ImageUrl="../../buttons/xfer.gif" runat="server"/>
>>
>> Why doesn't the checkbox (or radiobutton) work?
>>
>> Thanks,
>>
>> Tom

Nov 19 '05 #7

P: n/a
> > If an input html control, such as a regular button, or a checkbox,
has both client- and server-side onclick event assigned, asp.net
arranges it in the way

onclick="<javascript for client-side>; <javascript to invoke
server-side handler>;"


.. apart from the ";" inbetween, you have to add that yourself to your

(client-side) code!

No, asp.net does it for you if you have a server-side onclick event set. You
will find a __doPostBack... call over there.

For example, it will be produced for the following html:

<input type=button runat=server onclick="clientValidate()"
onserverclick="ServerValidate" ... >

Eliyahu
Nov 19 '05 #8

P: n/a

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:O%******************@TK2MSFTNGP12.phx.gbl...
Eliyahu Goldin wrote:
Tom,

If an input html control, such as a regular button, or a checkbox,
has both client- and server-side onclick event assigned, asp.net
arranges it in the way

onclick="<javascript for client-side>; <javascript to invoke
server-side handler>;"

.. apart from the ";" inbetween, you have to add that yourself to your
(client-side) code!


But I didn't have to for the linkbutton or imagebutton.

Tom
In your case you had

onclick="return confirm(...); <javascript to invoke server-side
handler>;"

Obviously, the javascript to invoke server-side handler never had its
chance to run.

For ImageButton, which renders as <input type=image>, asp.net
apparently arranges event handlers differently.

Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:uv**************@TK2MSFTNGP14.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eG**************@TK2MSFTNGP15.phx.gbl...
One more bracket:

XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you sure
you want copy these entries?'))return;")

That works fine now,

How come?

Why didn't the other one work if it worked with the asp:imageButton
and asp:linkbutton?

Thanks,

Tom
--
Eliyahu

"tshad" <tf*@dslextreme.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:ui**************@tk2msftngp13.phx.gbl...
>> Tom,
>>
>> Try
>>
>> XferToDefault.Attributes.Add("onclick", "if(!confirm('Are you
>> sure you want copy these entries?')return;")
>
> I tried that, but there must be a problem with the Javascript. I
> don't get the confirm box at all now, as well as not going to the
> function.
>
> Tom
>
>>
>> If it works, I can explain the reason.
>>
>> Eliyahu
>>
>> "tshad" <tf*@dslextreme.com> wrote in message
>> news:%2****************@TK2MSFTNGP09.phx.gbl...
>>> I have the following code that attaches a Javascript confirm box
>>> to my checkbox. When I select the checkbox, the window comes up
>>> fine, but it never executes the XfertoDefault_Click function
>>> when I press the Yes button. If I take off the Javascript event,
>>> the checkbox works fine.
>>>
>>> XferToDefault.Attributes.Add("onclick", "return confirm('Are you
>>> sure you want copy these entries?');")
>>>
>>> <asp:CheckBox ID="XferToDefault" AutoPostBack="true"
>>> OnCheckedChanged="XferToDefault_Click" runat="server"/>
>>>
>>> If I change the checkbox to an ImageButton, it all works fine -
>>> the Javascript window as well as going to the function after the
>>> Yes button is pressed.
>>> <asp:ImageButton ID="XferToDefault" OnClick="XferToDefault_Click"
>>> ImageUrl="../../buttons/xfer.gif" runat="server"/>
>>>
>>> Why doesn't the checkbox (or radiobutton) work?
>>>
>>> Thanks,
>>>
>>> Tom


Nov 19 '05 #9

P: n/a
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> If an input html control, such as a regular button, or a checkbox,
> has both client- and server-side onclick event assigned, asp.net
> arranges it in the way
>
> onclick="<javascript for client-side>; <javascript to invoke
> server-side handler>;"
>
.. apart from the ";" inbetween, you have to add that yourself to your

(client-side) code!

No, asp.net does it for you if you have a server-side onclick event set.
You
will find a __doPostBack... call over there.

For example, it will be produced for the following html:

<input type=button runat=server onclick="clientValidate()"
onserverclick="ServerValidate" ... >


So how is:

if(!confirm('Are you sure you want copy these entries?'))return;

different from:

return confirm('Are you sure you want copy these entries?');

That the 1st one works and the 2nd one doesn't?

Tom
Eliyahu

Nov 19 '05 #10

P: n/a
tshad wrote:
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
If an input html control, such as a regular button, or a checkbox,
has both client- and server-side onclick event assigned, asp.net
arranges it in the way

onclick="<javascript for client-side>; <javascript to invoke
server-side handler>;"
.. apart from the ";" inbetween, you have to add that yourself to
your (client-side) code!


No, asp.net does it for you if you have a server-side onclick event
set. You
will find a __doPostBack... call over there.

For example, it will be produced for the following html:

<input type=button runat=server onclick="clientValidate()"
onserverclick="ServerValidate" ... >


So how is:

if(!confirm('Are you sure you want copy these entries?'))return;

different from:

return confirm('Are you sure you want copy these entries?');

That the 1st one works and the 2nd one doesn't?

Tom

Eliyahu


return confirm() always returns (true or false)

if (!confirm()) return; only returns (without value) if *not* confirmed
and continues (with the postback presumably) if it *is* confirmed.

Hans Kesting
Nov 19 '05 #11

P: n/a
check boxes do not postback automatically. .net add client script (a call to
__doPostback), after any script you add. if your client code does a return,
the postback script will not be called.

-- bruce (sqlwork.com)
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> If an input html control, such as a regular button, or a checkbox,
> has both client- and server-side onclick event assigned, asp.net
> arranges it in the way
>
> onclick="<javascript for client-side>; <javascript to invoke
> server-side handler>;"
>

.. apart from the ";" inbetween, you have to add that yourself to your

(client-side) code!

No, asp.net does it for you if you have a server-side onclick event set.
You
will find a __doPostBack... call over there.

For example, it will be produced for the following html:

<input type=button runat=server onclick="clientValidate()"
onserverclick="ServerValidate" ... >


So how is:

if(!confirm('Are you sure you want copy these entries?'))return;

different from:

return confirm('Are you sure you want copy these entries?');

That the 1st one works and the 2nd one doesn't?

Tom

Eliyahu


Nov 19 '05 #12

P: n/a
"Bruce Barker" <br******************@safeco.com> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
check boxes do not postback automatically. .net add client script (a call
to __doPostback), after any script you add. if your client code does a
return, the postback script will not be called.
But in my case, I am doing an autoPostback=true and it does postback (if you
didn't have the old type of javascript connected to it).

Tom
-- bruce (sqlwork.com)
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> If an input html control, such as a regular button, or a checkbox,
> has both client- and server-side onclick event assigned, asp.net
> arranges it in the way
>
> onclick="<javascript for client-side>; <javascript to invoke
> server-side handler>;"
>

.. apart from the ";" inbetween, you have to add that yourself to your
(client-side) code!

No, asp.net does it for you if you have a server-side onclick event set.
You
will find a __doPostBack... call over there.

For example, it will be produced for the following html:

<input type=button runat=server onclick="clientValidate()"
onserverclick="ServerValidate" ... >


So how is:

if(!confirm('Are you sure you want copy these entries?'))return;

different from:

return confirm('Are you sure you want copy these entries?');

That the 1st one works and the 2nd one doesn't?

Tom

Eliyahu



Nov 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.