473,503 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Span onclick with checkbox problem

GTi
I want to use a 'smarter' checkbox using span. When a user press the
text the checkbox is checked. But this dos't work as expected. Any
idea?
<span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
<input type="checkbox" name="IsProd" value="1" />
Is a Product
</span>
function ClickBoxClick(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
if(el.checked) { el.checked=false; }
else { el.checked = true; }
}
}

Dec 14 '05 #1
16 7221
> "GTi" <tu****@gmail.com> wrote:
news:11**********************@g44g2000cwa.googlegr oups.com....

I want to use a 'smarter' checkbox using span. When a user press the
text the checkbox is checked. But this dos't work as expected. Any
idea?

<span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
<input type="checkbox" name="IsProd" value="1" />
Is a Product
</span>

function ClickBoxClick(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
if(el.checked) { el.checked=false; }
else { el.checked = true; }
}
}


This is what label is for.

<input id="mybox" type="checkbox" name="IsProd" value="1">
<label for="mybox" style="cursor:pointer;">Is a Product</label>

--
BootNic Wednesday, December 14, 2005 9:22 AM

Our earth is degenerate in these latter days; bribery and corruption are common; children no longer obey their parents; and the end of the world is evidently approaching.
*Assyrian clay tablet 2800 B.C.*

Dec 14 '05 #2
GTi
It shuld be:
<label for="mybox" style="cursor:pointer;">
<input id="mybox" type="checkbox" name="IsProd" value="1">
Is a Product</label>

But then I have another problem:
Using checkboxes in a form dosn't post back the result when it is not
checked. That is a problem. So my next step was to extend this function
with a hidden input fields with values 0 or 1 if the checkbox.
This solution does not solve that problem - or?

Dec 14 '05 #3
GTi wrote:
I want to use a 'smarter' checkbox using span. When a user press the
text the checkbox is checked. But this dos't work as expected. Any
idea?

<span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
<input type="checkbox" name="IsProd" value="1" /> ^^^^[1] ^[2]

[2] IE does not support XHTML.
Is a Product
</span>
<input type="checkbox" name="IsProd" id="IsProdID" value="1"><label
for="IsProdID">Is a Product</label>

No scripting is needed here at all, and the best of it is that it is
Valid HTML 4.01 Strict.
function ClickBoxClick(obj)
{
if(document.getElementsByTagName) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ {
var el = document.getElementById(obj); ^^^^^^^^^^^^^^^^^^^^^^^ if(el.checked) { el.checked=false; }
else { el.checked = true; }
}
}


Your script does not work because names are not IDs.[1]

You are insufficiently feature-testing the wrong property
and your indentation style allows for improvement, BTW.
PointedEars
Dec 14 '05 #4
GTi
OK my bad - the label can be almost anywhere on the page as long as it
ref to the id name.
But it will not solve my other problem I think.

Dec 14 '05 #5
GTi wrote:
It shuld be:
<label for="mybox" style="cursor:pointer;">
<input id="mybox" type="checkbox" name="IsProd" value="1">
Is a Product</label>
It CAN be, there is no MUST. However, experience shows that including
a label element for an ID that was not parsed yet is error-prone, so it
SHOULD NOT be as above but instead as BootNic and I posted.
But then I have another problem:
Using checkboxes in a form dosn't post back the result when it is not
checked. That is a problem.
That is no problem. Why would you be interested in unchecked checkboxes?
So my next step was to extend this function
with a hidden input fields with values 0 or 1 if the checkbox.
This solution does not solve that problem - or?


This "solution" introduces more problems than it "solves", for example
the dependency on client-side script support and thus the inevitable
unreliability of the posted data.
PointedEars
Dec 14 '05 #6
GTi

Thomas 'PointedEars' Lahn wrote:
But then I have another problem:
Using checkboxes in a form dosn't post back the result when it is not
checked. That is a problem.
That is no problem. Why would you be interested in unchecked checkboxes?

When the target page recieves the form it will not see that the
checkbox was on the form and leaves the value unchanged in the
database. But if I have a value telling it is turned off it will change
the value in the database. I know that this is by design, but I'm
trying to keep a common target page for all kind of changes in the
database (on one table). That way I can have several forms and only
display what fields I want to change with only one target page.
So my next step was to extend this function
with a hidden input fields with values 0 or 1 if the checkbox.
This solution does not solve that problem - or?


This "solution" introduces more problems than it "solves", for example
the dependency on client-side script support and thus the inevitable
unreliability of the posted data.
PointedEars


Dec 14 '05 #7
GTi wrote:
Thomas 'PointedEars' Lahn wrote:
> But then I have another problem:
> Using checkboxes in a form dosn't post back the result when it is not
> checked. That is a problem.

That is no problem. Why would you be interested in unchecked checkboxes?


When the target page recieves the form it will not see that the
checkbox was on the form and leaves the value unchanged in the
database. But if I have a value telling it is turned off it will change
the value in the database. I know that this is by design, but I'm
trying to keep a common target page for all kind of changes in the
database (on one table). That way I can have several forms and only
display what fields I want to change with only one target page.


So you just need to assume a default value server-side and
modify the database always or compare with the value in the
DB first, or use groups of two radiobuttons.
PointedEars
Dec 14 '05 #8
Thomas 'PointedEars' Lahn wrote:
GTi wrote:
I want to use a 'smarter' checkbox using span. When a user press the
text the checkbox is checked. But this dos't work as expected. Any
idea?

<span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
<input type="checkbox" name="IsProd" value="1" />

^^^^[1] ^[2]

[2] IE does not support XHTML.


But, apparantly, .NET seems to force it - I see that happen quite often
in .NET based pages.

..NET also has the runat="" attribute, which is not valid 4.01 strict,
either.

I'm just wondering if you have any suggestions on how to deal with that
(and don't say don't use .NET - it's not an option, unfortunately :( )
It's been a source of frustration to me for some time, but I have no
ideas how to deal with it.

Dec 14 '05 #9
GTi

Tony wrote:
Thomas 'PointedEars' Lahn wrote:
GTi wrote:
I want to use a 'smarter' checkbox using span. When a user press the
text the checkbox is checked. But this dos't work as expected. Any
idea?

<span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
<input type="checkbox" name="IsProd" value="1" />

^^^^[1] ^[2]

[2] IE does not support XHTML.


But, apparantly, .NET seems to force it - I see that happen quite often
in .NET based pages.

.NET also has the runat="" attribute, which is not valid 4.01 strict,
either.

I'm just wondering if you have any suggestions on how to deal with that
(and don't say don't use .NET - it's not an option, unfortunately :( )
It's been a source of frustration to me for some time, but I have no
ideas how to deal with it.


Yes - it is .NET and no I don't have any solution for that.
BUT i'm doing some "the hard way" by creating my own classes and tags.
I always use Firefox and IE to test my code. Firefox has many
extensions for HTML validations. And yes - it complains a lot about
..NET generated code.

Dec 14 '05 #10
Tony wrote:
Thomas 'PointedEars' Lahn wrote:
GTi wrote:
> I want to use a 'smarter' checkbox using span. When a user press the
> text the checkbox is checked. But this dos't work as expected. Any
> idea?
>
> <span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
> <input type="checkbox" name="IsProd" value="1" /> ^^^^[1] ^[2]

[2] IE does not support XHTML.


But, apparantly, .NET seems to force it -


That would be unfortunate (but typically M$), but I doubt that.
Do you get an error message or something if you omit the `/'?
If yes, what is it and with which code exactly does it occur?
I see that happen quite often in .NET based pages.
So?
.NET also has the runat="" attribute, which is not valid 4.01 strict,
either.


Do not mix up server-side and client-side code. AFAIK `runat' is used
server-side for Web Controls, it does not occur in client-side code.
(CMIIW, I never had a requirement for .NET)

Maybe someone in a .NET group knows something about that.
PointedEars
Dec 14 '05 #11
Thomas 'PointedEars' Lahn wrote:
Tony wrote:
Thomas 'PointedEars' Lahn wrote:
GTi wrote:
> I want to use a 'smarter' checkbox using span. When a user press the
> text the checkbox is checked. But this dos't work as expected. Any
> idea?
>
> <span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
> <input type="checkbox" name="IsProd" value="1" />
^^^^[1] ^[2]

[2] IE does not support XHTML.
But, apparantly, .NET seems to force it -


That would be unfortunate (but typically M$), but I doubt that.
Do you get an error message or something if you omit the `/'?
If yes, what is it and with which code exactly does it occur?


My understanding is that the input is built with a "controller" - some
sort of built-in class in the .NET framework. In order to omit the '/',
you would have to override the controller.
I see that happen quite often in .NET based pages.


So?


Given that I handle the front-end (HTML layout, CSS, Javascript) for a
..NET web application, it's a PITA.
.NET also has the runat="" attribute, which is not valid 4.01 strict,
either.


Do not mix up server-side and client-side code. AFAIK `runat' is used
server-side for Web Controls, it does not occur in client-side code.
(CMIIW, I never had a requirement for .NET)


It shows up in the HTML tag for form elements.
Maybe someone in a .NET group knows something about that.


Perhaps - it's not my thing, though. All I know is that .NET gives me
crappy code to have to work with. Ah well - back to JS...

Dec 14 '05 #12
On 2005-12-14, GTi <tu****@gmail.com> wrote:
It shuld be:
<label for="mybox" style="cursor:pointer;">
<input id="mybox" type="checkbox" name="IsProd" value="1">
Is a Product</label>
But then I have another problem:
Using checkboxes in a form dosn't post back the result when it is not
checked.


if you know what boxes there are in the form you can determine which ones
are not checked by their absense from the response.

if you are adding cheeckboxes dynamically and need to know of their
exiostance record it using a hidden field or fields.

Bye.
Jasen
Dec 15 '05 #13
On 2005-12-14, Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
GTi wrote:
I want to use a 'smarter' checkbox using span. When a user press the
text the checkbox is checked. But this dos't work as expected. Any
idea?

<span style="cursor:pointer;" onclick="ClickBoxClick('IsProd');">
<input type="checkbox" name="IsProd" value="1" />

^^^^[1] ^[2]

[2] IE does not support XHTML.


It seems to support the W3C validator page OK.

Bye.
Jasen
Dec 15 '05 #14
On 2005-12-14, GTi <tu****@gmail.com> wrote:

Thomas 'PointedEars' Lahn wrote:
> But then I have another problem:
> Using checkboxes in a form dosn't post back the result when it is not
> checked. That is a problem.
That is no problem. Why would you be interested in unchecked checkboxes?

When the target page recieves the form it will not see that the
checkbox was on the form and leaves the value unchanged in the
database.


that's a server side issue, are you using javascript on the server?
But if I have a value telling it is turned off it will change
the value in the database. I know that this is by design, but I'm
trying to keep a common target page for all kind of changes in the
database (on one table). That way I can have several forms and only
display what fields I want to change with only one target page.


you need to let the server know which checkboxes are on the form.
a hidden field that is populated the page is generated if probably the
easiest way to do this.

be aware that people may abuse your server by submitting forma of their own
creation, so check all critical fields to ensure that the submitter has the
right to modify that field.

we had a php script (we think) exploited today someone sent spam to a few
thousand people I left my boss going over the logs.

Bye.
Jasen
Dec 15 '05 #15
GTi
Jasen Betts wrote:
On 2005-12-14, GTi <tu****@gmail.com> wrote:

Thomas 'PointedEars' Lahn wrote:

> But then I have another problem:
> Using checkboxes in a form dosn't post back the result when it is not
> checked. That is a problem.

That is no problem. Why would you be interested in unchecked checkboxes?

When the target page recieves the form it will not see that the
checkbox was on the form and leaves the value unchanged in the
database.


that's a server side issue, are you using javascript on the server?
But if I have a value telling it is turned off it will change
the value in the database. I know that this is by design, but I'm
trying to keep a common target page for all kind of changes in the
database (on one table). That way I can have several forms and only
display what fields I want to change with only one target page.


you need to let the server know which checkboxes are on the form.
a hidden field that is populated the page is generated if probably the
easiest way to do this.

be aware that people may abuse your server by submitting forma of their own
creation, so check all critical fields to ensure that the submitter has the
right to modify that field.

we had a php script (we think) exploited today someone sent spam to a few
thousand people I left my boss going over the logs.

Bye.
Jasen


For this we WANT the end user to create it's own forms to submit to our
"form" collector. And it is a intranet site - so we don't have mutch
problem with abuse I think.

Dec 16 '05 #16
Jasen Betts wrote:
Thomas 'PointedEars' Lahn wrote:

<snip>
[2] IE does not support XHTML.


It seems to support the W3C validator page OK.


Then the W3C validator page, as served to IE, is not an XHTML document.
Remember that it is the HTTP content-type header that declares the type
of document when it is served over HTTP. That header is definitive, if
the mark-up does not correspond IE will attempt to error-correct it into
the appropriate type (or, more likely, a tag-soup approximation). IE
does not support XHTML.

Richard.
Dec 17 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
14088
by: Fabri | last post by:
I shoul want to know the content o a certain span: ************************************************************************ <html> <head> <title>Documento senza titolo</title> <meta...
6
2814
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down...
2
11645
by: Homa | last post by:
Hi, I have a Datagrid that uses as a shopping cart and have a checkbox template column in it. I can't add both OnCheckedChanged Event and onclick client script for it. I want to do two...
7
5452
by: Ryan Ternier | last post by:
I have a check box on my page. When a user clicks this box I have a confirmation box come up. When the user clicks OK, true is returned, otherwise false. Now, when true is Returened, I want...
5
3234
by: ste.paoletti | last post by:
I have a problem with css I have a this xhtml code: <span> <span> <span/> <input type="radio"/> .... <span/> <input type="button" onclick ="var s=document.createElement('span');...
1
3966
by: Fao, Sean | last post by:
I'm trying to set the title attribute on a CheckBox and I'm having some issues in ASP.NET 1.1. The title attribute in the following example is valid in HTML 4.01 Transitional: <input...
3
3031
by: juicy | last post by:
Hi, I have 4 check box and a textarea. When user check each check box, it will append text in the textarea. In onclick event, it calls getSurcharge function and append value in variable output....
7
2314
by: mavigozler | last post by:
IE7 does not appear to set an event on contained text inside SPAN elements whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML recommendation. Firefox appears to conform. ...
2
2506
by: swethak | last post by:
Hi, i am getting the problem when i used the onclick event in option tag.It is working fine in mozilla .But it is not working IE. Here is my code <script>
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.