In article <4c**************************@posting.google.com >,
me********@gmail.com enlightened us with...
Very basic, very simple, but I can't get a checkbox to check when the
value of a text field changes to something greater than 0.
Actually, not as simple as you'd think.
Textboxes are text. You're comparing text to a number. It's trying to convert
to compare, but what it does it is converts the number to text, so you get
the wrong kind of comparison.
Here's what I have:
THE javascript:
<script language=JavaScript>
type="text/javascript"
language is deprecated.
<!-- Begin
function sel_comm(comm_val)
{
if (comm_val > 0)
if (parseInt(comm_val,10) > 0)
<INPUT TYPE="checkbox" NAME="add_comm" ID="add_comm" VALUE="1">
Commission: <INPUT TYPE="text" NAME="item_comm" ID="item_comm"
size="6" onChange="sel_comm(this.value);">
Also note that the onChange event fires AFTER focus has left the element. I
don't know how good it is to use the 'this' keyword across browsers for that.
Anyone have any comments about that?
Oh, and I think value is undefined if there is no value in the box. So test
what happens if the user deletes the value and then moves focus. You may have
to test for 'not a number' conditions, too.
And your syntax in your function isn't cross-browser, either. If this is for
the internet, your best bet is
document.forms["inhouse-f2"].elements["add_comm"].checked = true;
HTH
--
--
~kaeli~
In democracy your vote counts. In feudalism your count votes.
http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace