473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Muhammad Abdullah | last post by:
Hi am having some problems with the javascript confirm. i have it working fine on one page and it doesnt even pop up at the other. The code on the working page is, private void...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.