Jump to content

form focus function


vzwhaley

Recommended Posts

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> &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);
}
?>[/code]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.