trouble with indexof for form value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy

    trouble with indexof for form value

    Hello,

    I am trying to validate a form wherein someone will enter their first
    and last name, fill out the form, then electronically "sign" at the
    bottom. I want to confirm that the first and last names match in the
    First & Last & Signature form fields. Here is the code I wrote, but
    it doesn't work because indexof is supposed to be a string. What do I
    need to do to fix this?

    if (document.repFo rm.Signature.va lue.indexOf(Fir st) == -1 ||
    document.repFor m. Signature.value .indexOf(Last) == "-1") {
    alert("Signatur e does not match first and last name.");
    document.repFor m.Signature.foc us();
    return false;}


    Thanks,

    Jeremy
  • Lee

    #2
    Re: trouble with indexof for form value

    Jeremy said:[color=blue]
    >
    >Hello,
    >
    >I am trying to validate a form wherein someone will enter their first
    >and last name, fill out the form, then electronically "sign" at the
    >bottom. I want to confirm that the first and last names match in the
    >First & Last & Signature form fields. Here is the code I wrote, but
    >it doesn't work because indexof is supposed to be a string. What do I
    >need to do to fix this?
    >
    >if (document.repFo rm.Signature.va lue.indexOf(Fir st) == -1 ||
    >document.repFo rm. Signature.value .indexOf(Last) == "-1") {
    >alert("Signatu re does not match first and last name.");
    >document.repFo rm.Signature.fo cus();
    >return false;}[/color]

    As you say, First and Last need to be strings, so simply
    assign them the values of the First and Last form fields,
    before you try to look for them in value of the Signature
    field.

    Comment

    • Chris Riesbeck

      #3
      Re: trouble with indexof for form value

      jeremy_zifchock @yahoo.com (Jeremy) wrote in message news:<f9d85033. 0310100636.3275 caf0@posting.go ogle.com>...[color=blue]
      > Hello,
      >
      > I am trying to validate a form wherein someone will enter their first
      > and last name, fill out the form, then electronically "sign" at the
      > bottom. I want to confirm that the first and last names match in the
      > First & Last & Signature form fields. Here is the code I wrote, but
      > it doesn't work because indexof is supposed to be a string. What do I
      > need to do to fix this?
      >
      > if (document.repFo rm.Signature.va lue.indexOf(Fir st) == -1 ||
      > document.repFor m. Signature.value .indexOf(Last) == "-1") {
      > alert("Signatur e does not match first and last name.");
      > document.repFor m.Signature.foc us();
      > return false;}[/color]

      If First is a field, then you need to use document.repFor m.First.value,
      and ditto Last.

      Comment

      Working...