472,121 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

Javascript not working

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
12 2043
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
"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
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
"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
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
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
> > 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

"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
"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
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
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
"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.

Similar topics

136 posts views Thread by Matt Kruse | last post: by
1 post views Thread by Muhammad Abdullah | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.