'On' or 'True' - which is it? Oct27 '05
I always find it slightly difficult to go from one programming language, to another.
For example, PHP and ASP can do pretty much the same thing, but both have vastly different syntax.
The same goes for JavaScript. The syntax is a bit different, than PHP - so I typically struggle to remember the proper syntax for certain things.
One example that came up recently involves HTML checkboxes. A typical checkbox element looks something like this:
<input type="checkbox" name="mycheckbox" id="mycheckbox" checked="checked" />
When a form, with this element, is submitted - both JavaScript and PHP return a different value, depending on whether or not the checkbox was checked.
JavaScript returns true, if the box was checked, or false if the box was not checked.
PHP, however, returns on, if the box was checked, and empty string (''), if the box was not checked.
Maybe this information will help someone out. I was stuck on it for a while - testing for PHP returning true, and never getting anything executed. It wasn’t until I realized it was returning true (in the normal sense of the word), but the actual output was on, instead of true.
Categories: JavaScript
, PHP ![]()
Add Feedback (view all)
Leave feedback
Sorry... yes, I am referring to the value of input.checked. Good points - yes, if you have more than one chec ... Read more.
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Popular Pages
- Fast rounded corners in Photoshop (4151 recent visits)
- PHP – passing variables across pages (1558 recent visits)
- JavaScript set selected on load (1290 recent visits)
- Removing all child nodes from an element (882 recent visits)
- iPod songs out of order? (747 recent visits)
- Britney - Everytime piano tab (669 recent visits)
- Firefox 3 smart address bar: wildcard search (633 recent visits)
- MySQL LEFT JOIN syntax (543 recent visits)
- Breathe Me - Sia (508 recent visits)
- Tumblr: how blogging should be (403 recent visits)
Similar Entries
- True Terror: The Hollywood Tower Hotel (0 recent visits)
- My true feelings about iTunes (0 recent visits)
Stats
2 unique visits since August 2008
I'm a little unsure what you mean about Javascript returning true for a checkbox... do you mean if you're testing input.checked? You're not reall ... Read more.