...

View Full Version : Resolved Checkbox always "on"



mlse
09-25-2008, 09:09 AM
Hi all,

Consider the following code:

HTML snippet, submits to test.php:


<form name="myform" method="post" action="test.php">
<input type="checkbox" name="test" />
<input type="submit" onclick="alert(document.forms['myform'].elements[0].value);" />
</form>


And test.php is as follows:


<?php echo $_REQUEST["test"]; ?>


The PHP displays on when the checkbox is checked and nothing at all when it isn't, as you would expect.

However, the javascript alert always displays on regardless of whether or not the checkbox is checked.

Strange, n'est pas? Pourquoi?!

TIA,

Mike.

vwphillips
09-25-2008, 09:20 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<form name="myform" method="post" action="test.php">
<input type="checkbox" name="test" />
<input type="submit" onclick="alert(document.forms['myform'].elements[0].checked);" />
</form>
</body>

</html>

mlse
09-25-2008, 09:29 AM
Danke shoen! Das ist einfach :)

(Mike is in a multi-lingual mood today!).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum