vzwhaley Posted March 7, 2006 Share Posted March 7, 2006 Hello everyone and thanks much for your past help.On my current project, I have created an "E-mail Story to a Friend" script with a form that has three fields that are being validated. I simply want the cursor to land on the first field that is not validated. In other words, the three fields for validation are To (the e-mail address for the recipient), Name (the name of the person sending the story), and E-mail (the sender's e-mail address). So if the To field is validated true, then the cursor should focus on the Name field, and if the To and Name fields are validated true, then the cursor should focus on the E-mail field. Make sense? I am new to php functions and have the following code, which does not work. Any suggestions would be much appreciated![code]<?session_start();function LoginErrorFocus($FieldNum) {if (strlen($FieldNum) > 0 && strlen($FieldNum) < 3) { if ($FieldNum == "01") { $fOnLoad = "document.EmailObit.txtTo.focus()"; return false; } if ($FieldNum == "02") { $fOnLoad = "document.EmailObit.txtName.focus()"; return false; } if ($FieldNum == "03") { $fOnLoad = "document.EmailObit.txtEmail.focus()"; return false; } } return;} $FieldNum = "";$fOnLoad = "document.EmailObit.txtTo.focus()";if ($_SESSION['Errors'] == 0) { $Instruction = "Please fill in the following form and a copy of this obituary will be sent to the e-mail address(es) you provide. Please separate multiple e-mail addresses with a comma. The <i>Johnson City Press</i> does not keep records of e-mail addresses when you e-mail an obituary to a friend.<br><font color=#FF0000><br>* Denotes a required field</font>";} else { $_SESSION['Errors'] = "0"; $Instruction = "<font color=FF0000>There are errors in your data. Please make the following changes:</font> ";} if ($_SESSION['BadTo'] == "T") { $eEmail = "<br><span class=Author><font color=FF0000>Please enter a valid e-mail address.</font></span>"; $_SESSION['BadTo'] = "F"; $FieldNum = $FieldNum."01"; LoginErrorFocus($FieldNum);} if ($_SESSION['BadName'] == "T") { $eName = "<br><span class=Author><font color=FF0000>Please enter your name.</font></span>"; $_SESSION['BadName'] = "F"; $FieldNum = $FieldNum."02"; LoginErrorFocus($FieldNum);} if ($_SESSION['BadEmail'] == "T") { $eEmail2 = "<br><span class=Author><font color=FF0000>Please enter a valid e-mail address.</font></span>"; $_SESSION['BadEmail'] = "F"; $FieldNum = $FieldNum."03"; LoginErrorFocus($FieldNum);} ?>[/code] Quote Link to comment Share on other sites More sharing options...
jordie Posted March 7, 2006 Share Posted March 7, 2006 In your LoginError Focus, change each "return false;" to return true; and the last one return; to the same reutnr true;. You have no reason to make this function fail... Quote Link to comment Share on other sites More sharing options...
vzwhaley Posted March 7, 2006 Author Share Posted March 7, 2006 thanks, jordie. unfortunately, that didn't help either. i rewrote the code like this, but it still can't exit out of the function once it determines if a value is true or false. any other suggestions?[code]function LoginErrorFocus($FieldNum) { if ($FieldNum == "01") { return "document.EmailObit.txtTo.focus()"; exit(); } elseif ($FieldNum == "02") { return "document.EmailObit.txtName.focus()"; exit(); } elseif ($FieldNum == "03") { return "document.EmailObit.txtEmail.focus()"; exit(); } else { return $fOnLoad = "document.EmailObit.txtTo.focus()"; exit(); }}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.