'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

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

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.

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.

Contact Matt

Popular Pages

  1. Fast rounded corners in Photoshop (4151 recent visits)
  2. PHP – passing variables across pages (1558 recent visits)
  3. JavaScript set selected on load (1290 recent visits)
  4. Removing all child nodes from an element (882 recent visits)
  5. iPod songs out of order? (747 recent visits)
  6. Britney - Everytime piano tab (669 recent visits)
  7. Firefox 3 smart address bar: wildcard search (633 recent visits)
  8. MySQL LEFT JOIN syntax (543 recent visits)
  9. Breathe Me - Sia (508 recent visits)
  10. Tumblr: how blogging should be (403 recent visits)

Similar Entries

Stats

2 unique visits since August 2008

Syndicate

Advertisements