Hi Helen,
Here is one solution that uses both.
PHP Code:
<?php session_start(); ?>
<script language="javascript" src="test7.php"></script>
<?php
if( $_SESSION['js_clear_active'] == FALSE) {?>
<form id="my_form" action='./next.php'>
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br /><br />
<input type="submit" name="submit" value="Submit"></a>
</form>
</form>
<form id='php_clear_form' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" accept-charset="utf-8"> <!-- When this posts it reloads the page -->
<input type="submit" name="clear" value="Reset Form"></a>
</form>
<?php } else {?>
<form id="my_form" action='./next.php'>
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br /><br />
<input type="submit" name="submit" value="Submit"></a>
<input type="button" name="reset_form" value="Reset Form" onclick="this.form.reset();">
</form>
<?php }?>
You use the
HTML Code:
<script language="javascript" src="test7.php"></script>
To determine if JavaScript is turned on. It run only if JavaScript can parse the script tag and will call a simple php page test7.php:
PHP Code:
<!-- test7.php -->
<?php
session_start();
$_SESSION['js_clear_active'] = TRUE;
?>
If you test it with JavaScript turned on first then to test that Javascript off works you will need to issue a $_SESSION['js_clear_active'] = 0; command to clear the session; otherwise your script clear button will appear but have not javascript support. Once you issue $_SESSION['js_clear_active'] = 0; then comment it out and try with Javascript off.
If you decide to use this then you should get the session to clear more cleanly.
Most people will have JavaScript either on or off, but there are those that disable it on the fly, so by cleaning the session if Javascript is not turned on then even the 'change on the fly' crowd will get a way to clear the form.
Hope this helps,
Steve
Bookmarks