here is a code fragment which I have cut and simplified from one of my working scripts, that does some simple javascript checking of a form. It should give you an idea of how to do it. There is a lot of documentation, and examples of javascript on the web. Try a google search. At this level it is relatively easy(well at least it is after you have done it once). When you get into more complicated javascripts, you have to take into account that because of different document object models, some things are implemented differently in different browsers.
. . .
?>
<head>
<script LANGUAGE="JavaScript">
<!-- Hide from older browsers
var whitespace = " \t\n\r";
function isEmpty(s) {
// +--------------------------------------+
// | Return true if the string s is empty |
// +--------------------------------------+
return ((s == null) || (s.length == 0))
}
function isWhitespace (s) {
// +-------------------------------------------------------+
// | Return true if s is empty or contains only whitespace |
// +-------------------------------------------------------+
var i;
if (isEmpty(s)) {
return true;
}
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1) return false;
}
return true;// must be whitespace
}
function checkRegisterScreen (form) {
// +-----------------------------------------------+
// | Return true if all fields on screen are valid |
// +-----------------------------------------------+
if (isWhitespace(form.userid.value)) {
alert("Userid may not be blank");
form.userid.focus();
return false;
}
if (isWhitespace(form.username.value)) {
alert("User name may not be blank");
return false;
}
return true;
}
// End of hidden section -->
</script>
</head>
<body>
<form name='RegisterForm' action='Register.php' method=post onSubmit='return checkRegisterScreen(this)' >
<?php
. . .
The key thing to notice here, is that the submit will only happen if the onSubmit returns true.
Hope this helps. . . Fred
Michael Eacott wrote:
Alex
Like you I have php scripts that validate the contents of registration and other forms. I'm new to php and do not have a clue about client side (java) scripting. Yes and the GO BACK AND TRY AGAIN process is what my php scripts do. All very messy. I'll have to learn javascript but currently I have a deadline to meet with the php implementation.Be interested to see sometime in the future the javascripts you write to validate you forms.
Regards
Mike Eacott
rentAweek Ltd
http://www.rentaweek.org
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php