Computing.Net > Forums > Web Development > Auto-check a check box on edit

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Auto-check a check box on edit

Reply to Message Icon

Name: jb60606
Date: July 2, 2007 at 11:58:14 Pacific
OS: Windows XP
CPU/Ram: 2.8Ghz/512MB
Product: Homeade
Comment:

How can I auto-check a checkbox when a corresponing textfield is edited?

For example, when textfield1 is clicked on or edited, checkbox1 will automatically "tick".

Anyone know of a link or tutorial on how to do so? I've googled it, though the closest I could find was the "check-all/un-check all" method.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: July 2, 2007 at 16:24:50 Pacific
Reply:

if they're in the same form, add this on the text field:

<input onfocus="this.form.THECHECKBOXNAME.checked=true" type="text" name="etc...

---
JakartaSpot.com


0

Response Number 2
Name: jb60606
Date: July 2, 2007 at 17:40:11 Pacific
Reply:

Thanks for your help.

I gave it a try, though it doesn't seem to work. I'm getting the error:

'this.form.checkbox.225' is null or not an object

I guess I should have mentioned that it's an array of checkboxes, each with a unique identifier given to it by PHP code.

The checkbox is formed like:

<input name="checkbox[<?php echo $row['id'];?>]" type="checkbox"...

My input field code with your javascript:

<input onfocus="this.form.checkbox[<?php echo $row['id'];?>].checked=true" type="text" name="e_price[<? echo $row['id'];?>]...

Looking at the HTML (below), it looks like I'm getting the right results, though for some reason it won't work. Any ideas?

<td><div align="center"><input name="checkbox[225]" type="checkbox" value="225"></div></td>
<td><input onfocus="this.form.checkbox[225].checked=true" type="text" name="sym[225]" value="AAPL"></td>
<td><input onfocus="this.form.checkbox[225].checked=true" onclick="ds_sh(this);" name="e_date[225]" value="2007-05-22" readonly="readonly" style="cursor: text" /></td>
<td width="125"><input onfocus="this.form.checkbox[225].checked=true" type="text" name="e_price[225]" value="85.45"></td>



0

Response Number 3
Name: Laler
Date: July 3, 2007 at 02:12:29 Pacific
Reply:

Hi,

I'm not sure on how to refer (in JavaScript) to a field name with box brackets. It might be possible, but maybe not. Can somebody confirm?

But if I need to create something like yours, I'll refer to the field ID, or by using those "JavaScript object thingy" :D Like "on focus, look at parent node's first checkbox, then mark it as checked".

Anyways, take a look here, view the source, and the PHP source.

It's the first example (referring to the checkbox ID).

The wrapped JavaScript function - checkTheBox(boxID) - is used to minimize potential headaches when doing these things in a not-so-simple applications.

---
JakartaSpot.com


0

Response Number 4
Name: jb60606
Date: July 3, 2007 at 13:52:44 Pacific
Reply:

Thanks.

It's weird, I tried your examples and I received the desired results (by changing the parenthesis to brackets in the jscript function), in the HTML code at least, though it still doesn't auto-check. Oh well.


0

Response Number 5
Name: Laler
Date: July 3, 2007 at 15:09:42 Pacific
Reply:


> by changing the parenthesis to brackets in the jscript function

can't do that. it must read like this:

getElementByID(ID_of_the_object)

Maybe you're confusing name and ID?

in my example, the checkbox field name is "checkbox[1]" and the ID is "c1", and so on.

'c' + boxID
will be parsed as "c1", and so on...

Forget the first part of my previous message. I read it again, and I'm confused -_-

Just check and try to recreate the sample. I think it's quite similar with your apps, including your PHP.

---
JakartaSpot.com


0

Related Posts

See More



Response Number 6
Name: jb60606
Date: July 3, 2007 at 22:52:11 Pacific
Reply:

You're a genious! It works. I overlooked the little "c" in front of the checkbox ID.

It works like a gem - thanks for your help.


0

Sponsored Link
Ads by Google
Reply to Message Icon

PHP/MYSQL updating w/chec... Is this possible?



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Auto-check a check box on edit

Auto refreshing a page once loaded www.computing.net/answers/webdevel/auto-refreshing-a-page-once-loaded/2367.html

auto scan folder and create links www.computing.net/answers/webdevel/auto-scan-folder-and-create-links-/2723.html

making money on net ? Possible? www.computing.net/answers/webdevel/making-money-on-net-possible/858.html