Jump to content


Photo

form focus function


  • Please log in to reply
2 replies to this topic

#1 vzwhaley

vzwhaley
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 07 March 2006 - 01:49 AM

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!

<?
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> &nbsp;";
} 

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);
} 
?>


#2 jordie

jordie
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 March 2006 - 02:48 AM

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...

#3 vzwhaley

vzwhaley
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 07 March 2006 - 06:45 PM

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?
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();
    }
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users