Checkboxes

S

Selrak

Hi,

I have a variable number of checkboxes in a form. I have developped a simple
function to calculate a number whith the quantity of checkboxes checked. I
put de JS function in onChange or in onClick whith the same problem:
Function don't execute but after checkbox clicked loses his focus and,
sometimes, if you click in another checkbox inmediatly after a first one,
don't execute the function at all, and I lose information. Any ideas of what
can be the problem?

Thanks for your interest.

Selrak
 
S

Selrak

Sorry, I suposed that the code wasn't important for this problem, because,
the code does the expected, but only sometimes the event executes it. Here
goes:

function newImport(document,boolean_canvi,cost)
{
var texteImport = docu.getElementsByName("import_texte");
var cost2;

if(boolean_canvi)
cost2= parseFloat(cost);
else
cost2= parseFloat(cost) * (-1);

texteImport[0].value = (parseFloat(texteImport[0].value) + cost2);
}

I call the function on
<input type="checkbox" onChange="JavaScript:
newImport(document,this.checked,1.00);" /> //The number 1.00 is an example.
In my code is a PHP variable.

Thanks

Selrak
 
C

CryingClinton

I guess the following may help a little:

-----------------------------------------------------------
<script>
function show_click(o)
{
document.getElementById('t1').value+="\r\nonclick fires: "+o.checked;
}

function show_change(o)
{
document.getElementById('t1').value+="\r\nonchange fires: "+o.checked;
}
</script>
<input type=checkbox onclick='show_click(this)'
onchange='show_change(this)'>
<textarea id=t1 rows=20 cols=50></textarea>
----------------------------------------------------------

The test code shows the onchange event never fires at the 'input
type=checkbox' object.

ccton

--
www.vicdir.com
Selrak said:
Sorry, I suposed that the code wasn't important for this problem, because,
the code does the expected, but only sometimes the event executes it. Here
goes:

function newImport(document,boolean_canvi,cost)
{
var texteImport = docu.getElementsByName("import_texte");
var cost2;

if(boolean_canvi)
cost2= parseFloat(cost);
else
cost2= parseFloat(cost) * (-1);

texteImport[0].value = (parseFloat(texteImport[0].value) + cost2);
}

I call the function on
<input type="checkbox" onChange="JavaScript:
newImport(document,this.checked,1.00);" /> //The number 1.00 is an example.
In my code is a PHP variable.

Thanks

Selrak

CryingClinton said:
Post ur whole codes out.

ccton
checked.
I of
what
 
S

Selrak

Thanks, I see that onClick is the event I'm looking for, however as you can
note, if you clikc two times too fast, it loses events :(

CryingClinton said:
I guess the following may help a little:

-----------------------------------------------------------
<script>
function show_click(o)
{
document.getElementById('t1').value+="\r\nonclick fires: "+o.checked;
}

function show_change(o)
{
document.getElementById('t1').value+="\r\nonchange fires: "+o.checked;
}
</script>
<input type=checkbox onclick='show_click(this)'
onchange='show_change(this)'>
<textarea id=t1 rows=20 cols=50></textarea>
----------------------------------------------------------

The test code shows the onchange event never fires at the 'input
type=checkbox' object.

ccton

--
www.vicdir.com
Selrak said:
Sorry, I suposed that the code wasn't important for this problem, because,
the code does the expected, but only sometimes the event executes it. Here
goes:

function newImport(document,boolean_canvi,cost)
{
var texteImport = docu.getElementsByName("import_texte");
var cost2;

if(boolean_canvi)
cost2= parseFloat(cost);
else
cost2= parseFloat(cost) * (-1);

texteImport[0].value = (parseFloat(texteImport[0].value) + cost2);
}

I call the function on
<input type="checkbox" onChange="JavaScript:
newImport(document,this.checked,1.00);" /> //The number 1.00 is an example.
In my code is a PHP variable.

Thanks

Selrak

CryingClinton said:
Post ur whole codes out.

ccton

--
www.vicdir.com
"Selrak" <[email protected]> ????
Hi,

I have a variable number of checkboxes in a form. I have developped a
simple
function to calculate a number whith the quantity of checkboxes
checked.
I
put de JS function in onChange or in onClick whith the same problem:
Function don't execute but after checkbox clicked loses his focus and,
sometimes, if you click in another checkbox inmediatly after a first one,
don't execute the function at all, and I lose information. Any ideas of
what
can be the problem?

Thanks for your interest.

Selrak
 
C

CryingClinton

I dont think so.

Man handing a mouse can not faster than computer, never! :)

even you focus on the selectbox and press ENTER (this will fire onclick
event as well), the computer still faster than you, nothing will be losed.

ccton
--
www.vicdir.com
Selrak said:
Thanks, I see that onClick is the event I'm looking for, however as you can
note, if you clikc two times too fast, it loses events :(

CryingClinton said:
I guess the following may help a little:

-----------------------------------------------------------
<script>
function show_click(o)
{
document.getElementById('t1').value+="\r\nonclick fires: "+o.checked;
}

function show_change(o)
{
document.getElementById('t1').value+="\r\nonchange fires: "+o.checked;
}
</script>
<input type=checkbox onclick='show_click(this)'
onchange='show_change(this)'>
<textarea id=t1 rows=20 cols=50></textarea>
----------------------------------------------------------

The test code shows the onchange event never fires at the 'input
type=checkbox' object.

ccton

--
www.vicdir.com
Selrak said:
Sorry, I suposed that the code wasn't important for this problem, because,
the code does the expected, but only sometimes the event executes it. Here
goes:

function newImport(document,boolean_canvi,cost)
{
var texteImport = docu.getElementsByName("import_texte");
var cost2;

if(boolean_canvi)
cost2= parseFloat(cost);
else
cost2= parseFloat(cost) * (-1);

texteImport[0].value = (parseFloat(texteImport[0].value) + cost2);
}

I call the function on
<input type="checkbox" onChange="JavaScript:
newImport(document,this.checked,1.00);" /> //The number 1.00 is an example.
In my code is a PHP variable.

Thanks

Selrak

"CryingClinton" <[email protected]> escribi?en el mensaje
Post ur whole codes out.

ccton

--
www.vicdir.com
"Selrak" <[email protected]> ????
Hi,

I have a variable number of checkboxes in a form. I have
developped
a ideas
of
 
R

rf

I dont think so.
Man handing a mouse can not faster than computer, never! :)

I *do* think so, in this instance.

Two very quick mouse clicks are translated into a doubleclick.

The sequence of events is:
onmousedown, onmouseup, onclick, onmouseup, ondblclick

There is only one onclick event. The second "onclick event" is translated
into an ondblclick so the second "onclick event" appears to be lost.

The OP should handle ondblckick events.
 
C

CryingClinton

I do agree with the ondblclick part.

The page interface should notice the users what's happenning due to their
operation so that they can re-click or something to get the right result. I
mean the page should display the results somewhere, otherwise there always
have troubles.

ccton
 
S

Selrak

Thanks for your answers. I'll try with onDoubleClick event. I'm allways
learning :)

Selrak
 
T

Thomas 'PointedEars' Lahn

Selrak said:
Thanks, I see that onClick is the event I'm looking for, however
as you can note, if you clikc two times too fast, it loses events :(

It is because that double-click is handled by a different event handler,
called "ondblclick". You can probably use event-bubbling in those UAs:

function form_ondblclick(e)
{
var t = (e && e.target || event.srcElement);
(t.click
? t.click(event)
: t.onclick
? t.onclick()
: void 0);
}

<form ... ondblclick="form_ondblclick(event)" ...>

Note: This is partly using proprietary behavior. There is no "dblclick"
event in the W3C DOM Level 2 Events Specification or a [on]click()
method, only an "ondblclick" event handler attribute in the HTML 4.01
Specification.

Please do not top-post. <http://www.jibbering.com/faq/#FAQ2_3>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top