This is a discussion on "[SOLVED] Automatic Checkbox/Radio Button Checking" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Automatic Checkbox/Radio Button Checking are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] Automatic Checkbox/Radio Button Checking
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Hello everyone,
I am having another small issue. I have a code that makes my viewers' lives a bit easier by automatically checking a radio button or checkbox when another radio button or checkbox is clicked. I will explain further. There are two parts to this issue. Part I) The form and code: The form looks like this:
Here is the code I have so far:
The radio buttons have an onclick value of: onclick="for(i=0;i<this.form.Checkboxes.length;i++ )this.form.problem[i].checked=0;". The textbox (after Checkbox3) has an onfocus value of: onfocus="this.form.problem[2].checked=true;selectFields();". The script works, but Internet Explorer says "Error on page" in the status bar, telling me that something is wrong... Part II) Form field names Now, in my code, I use "Checkboxes" as the names for all three checkboxes. However, I need a different name for each one since my php code (which submits the form content to me by email) would overwrite the checkbox values if more than one is checked. Now, different names would require difficult coding, which I don't really know how to do Any help on this would be greatly appreciated. Cheers and thanks, SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 25th, 2007 at 23:58. |
|
|
|
#2
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
Ok man, here is my solution.. i have added some comments, so i hope it is self explaining!
|
|
#3
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
Great! It seems to be working. How would I clear the textbox though? Same way, just have the code scan for an input field with a certain name?
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
#4
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
O__O Woah! I have totally forgotten that textfield! Sorry. Added it below. It will check the first radiobutton and the last checkbox when you press a key inside. When clicking another radio button, the text will be deleted.
|
|
#5
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
Great. Just one more question: is there a way to use onfocus for the textbox instead of onkeyup? I know it makes more sense to use keyup in order to make sure there is something in the textbox, but I think it would look better (user's point of view) if as soon as they click inside the textbox, the first radio and the last checkbox are checked. Then, to make sure that something is in the textbox if the last checkbox is checked, I can use my php validation. OR, I could use onfocus and clear the first radio and the last checkbox if nothing is in the textbox and the user clicks outside the textbox (onblur).
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 27th, 2007 at 01:55. |
|
#6
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
Sure. Just replace "onkeyup" with "onfocus"!
Have fun! |
|
#7
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
I tried to use onfocus, but it doesn't work since there needs to be at least one character in the textbox (according to your code).
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
#8
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
Jeah, if you do not want the test if there is anything in the textbox, then eliminate the condition.
Replace
|
|
#9
|
|||
|
|||
|
Re: Automatic Checkbox/Radio Button Checking
OK. I used this code to set it all up. I just can't get the php to display an error when the checkbox next to the text field is checked but the text field is empty (What was originally achieved with:
I will post a thread in the php forum about this. Thanks for all your help!
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Automatic Button 'Looping' for Navigation | starrzo | JavaScript Forum | 2 | Apr 4th, 2008 14:38 |
| [SOLVED] Selected radio button value | Pugger | JavaScript Forum | 8 | Nov 3rd, 2007 12:16 |
| [SOLVED] Radio Button Response! :( | jahphill | PHP Forum | 33 | Oct 25th, 2007 22:15 |
| [SOLVED] large radio button form submit | chriscant | JavaScript Forum | 7 | Oct 25th, 2007 09:03 |
| automatic pop-up when click on a radio button | joshcxa | JavaScript Forum | 2 | Aug 1st, 2006 06:06 |