| | |
Accessing HTML checkboxes with php and javascript
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2006
Posts: 19
Reputation:
Solved Threads: 0
Hi! I am having problems validating my HTML to at least transitional due to my use of checkboxes and accessing them with PHP and javascript. I want client-side validation and server side functionality and therefore am utilizing PHP and JS.
My understanding is that JS recognizes checkboxes to be an array by repeating the "name" attribute in multiple input tags. PHP recognizes checkboxes to be an array by repeating the "name" attribute followed by an empty subscript. name[]. In order to get both PHP and javascript to recognize i've set all my id attributes to the same name and all my name attributes to the same name plus the []. Here's some of my code.
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 8:00 a.m." /> 8:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 9:00 a.m." /> 9:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 10:00 a.m." /> 10:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 11:00 a.m." /> 11:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 12:00 p.m." /> 12:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 1:00 p.m." /> 1:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 2:00 p.m." /> 2:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 3:00 p.m." /> 3:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 4:00 p.m." /> 4:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 5:00 p.m." /> 5:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, evening" /> 6:00 - 9:00 p.m.
Obviously, the repetition of the id attribute is a violation for validation. Any suggestions on what I could do?
Thanks in advance for any suggestions.
Tara
My understanding is that JS recognizes checkboxes to be an array by repeating the "name" attribute in multiple input tags. PHP recognizes checkboxes to be an array by repeating the "name" attribute followed by an empty subscript. name[]. In order to get both PHP and javascript to recognize i've set all my id attributes to the same name and all my name attributes to the same name plus the []. Here's some of my code.
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 8:00 a.m." /> 8:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 9:00 a.m." /> 9:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 10:00 a.m." /> 10:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 11:00 a.m." /> 11:00 a.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 12:00 p.m." /> 12:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 1:00 p.m." /> 1:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 2:00 p.m." /> 2:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 3:00 p.m." /> 3:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 4:00 p.m." /> 4:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, 5:00 p.m." /> 5:00 p.m.<br />
<input type="checkbox" id="availcheck" name="availcheck[]" value="Monday, evening" /> 6:00 - 9:00 p.m.
Obviously, the repetition of the id attribute is a violation for validation. Any suggestions on what I could do?
Thanks in advance for any suggestions.
Tara
getElementByName() is not supported on all browsers.
The DOM functions getElementsByTagName and getAttribute are more supported.
Try a function like which uses those two to get the same result:
The DOM functions getElementsByTagName and getAttribute are more supported.
Try a function like which uses those two to get the same result:
PHP Syntax (Toggle Plain Text)
/** * Retrive an HTML Element Collection By name * @return Array HTML Elements * @param Object Parent Element * @param String name * @param String Tag name to limit search to */ function getElementsByName(parent, name, tag) { var els = new Array(); var allChildren = parent.getElementsByTagName(tag || '*'); for (var i = 0; i < allChildren.length; i++) { var child = allChildren[i]; if (child.getAttribute('name') == name) { els.push(child); } } return els; }
Last edited by digital-ether; Jan 13th, 2007 at 12:41 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Capturing data from txt file using JavaScript/HTML (JavaScript / DHTML / AJAX)
- how to access accessing PHP variable in JavaScript (PHP)
- how to extract data from javascript into php (PHP)
- html checkboxes... (PHP)
- Help modify some JavaScript/HTML (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: Matrix Script
- Next Thread: How to best rank items based on vote data
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






