hwg-languages archives | May 2001 | new search | results | previous | next |
Re: Netscape onclick eventby "Derek Lavine" <derek(at)realware.com.au> |
|
Thanks for the input guys. In case this is a help to anyone what I have below works. What this allows is for a user to enter details in to the form fields and depending on what button (graphic) is clicked a different form action is run. The code below works in both IE and NS. I could not use <input type="image" src="myimage.gif" ... onclick="formActionSet()"> as NS does not handle this properly. In the end I have used <a href="#" onClick="formActionSet('login')"><img src="myimage.gif"></a> Then in formActionSet() I set the command to be performed e.g. document.login.action = "../login/login_cmd.cfm"; I then call submitForm() which checks the fields for valid content using the action set in formActionSet() to decide which fields to check (in this case only the userName and password fields are checked. And if all is ok submitForm() actually calls document.login.submit(); which actually submits the form to the server. I hope this is of help to someone. Of course you may know much better ways of doing this. Cheers Derek <html> <head> <title>Untitled</title> <script language="JavaScript"> <!-- function submitForm() { if (document.login.action.indexOf("login_cmd.cfm") != -1){ if (document.login.f_userName.value == "") { alert("Please enter your user name"); document.login.f_userName.focus(); return false; } if (document.login.f_password.value == "") { alert("Please enter your password"); document.login.f_password.focus(); return false; } } document.login.submit(); return true; } function formActionSet(obj) { if (obj == "login"){ document.login.action = "../login/login_cmd.cfm"; } else { document.login.action = "../site_selection/main_selection.cfm?a_guest=1"; } return submitForm(); } //--> </script> </head> <body> <cfform name="login" action="login_cmd.cfm" method="post" onSubmit="return submitForm()"> <input type="Text" name="f_userName" required="No" size="12"> <input type="password" name="f_password" style="" required="No" size="12"> <a href="#" name="login" onclick="formActionSet('login')"><img name="login2" src="login_button.gif"></a> <a href="#" name="guest" onclick="formActionSet('guest')"><img name="guest2" src="guest_button.gif"></a> </body> </html>
HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA