Form problem??

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

    Form problem??

    I want to create a script that prevent users of my form for typeing stupid
    things.
    Here is my script:
    <script language="JavaS cript" type="text/JavaScript">
    <!--
    function provjera(s1, s2, s3, s4) {
    var ime1 = document.formul ar.ime;
    var email1 = document.formul ar.email;
    var mob1 = document.formul ar.mob;
    var izbornik1 = document.formul ar.izbornik;
    var obj1 = document.getEle mentById("s1");
    var obj2 = document.getEle mentById("s2");
    var obj3 = document.getEle mentById("s3");
    var obj4 = document.getEle mentById("s4");

    if (ime1.value.ind exOf(" ") == -1) {
    obj1.style.disp lay = "block";
    ime1.focus();
    }
    else obj1.style.disp lay = "none";
    if ((email1.value. indexOf("@") == -1) || (email1.value.i ndexOf(".") == -1))
    {
    obj2.style.disp lay = "block";
    email1.focus();
    }
    else obj2.style.disp lay = "none";
    if (mob1.length == 0) {
    obj3.style.disp lay = "block";
    mob1.focus();
    }
    else obj3.style.disp lay = "none";
    if (izbornik1.sele ctedIndex == 0) {
    obj4.style.disp lay = "block";
    izbornik1.focus ();
    } else {
    obj4.style.disp lay = "none";
    document.formul ar.submit(); // Kaze da u ovom redu nesto ne valja
    }
    }
    //-->
    </script>

    In Firefox it is good but Internet Explorer always want to debug.
    He seys:
    Line: 62
    Error:Object doesn't support this property or method




    Please Help m!!!!!


    How I fix this??????????


  • Mikhail Esteves

    #2
    Re: Form problem??

    kec wrote:[color=blue]
    > I want to create a script that prevent users of my form for typeing stupid
    > things.[/color]

    What kind of input are you trying to validate? If its only to block
    weird characters from an ordinary textbox, why not use a Regular
    Expression instead?

    function IsLegal(str){
    // Checks for @ ( ) < > [ ] , ; : \ / "
    var badchars = /[\@\(\)\<\>\,\;\ :\\\/\"\[\]]/
    if (str.match(badc hars))
    return false;
    else
    return true;
    }

    if (!IsLegal(Form. TextBox.Text))
    {
    alert("Illegal characters in TextBox. Please try again!");
    }

    HTH.

    Mikhail

    Comment

    • kec

      #3
      Re: Form problem??

      Form:
      <form name="formular" action="kontakt i2.php" method="post">
      <table width="477" border="0">
      <tr>
      <td colspan="2"><di v align="center">
      <p><strong>Obra zac za kontakt </strong></p>
      <p>&nbsp;</p>
      </div></td>
      </tr>
      <tr>
      <td width="213" rowspan="2">Vas e ime i prezime: </td>
      <td width="248"><p align="left">
      <input name="ime" type="text" size="41"></p>

      </td>
      </tr>
      <tr>
      <td><div style=" color:#FF0000; display:none" id="s1">Upisit e svoje ime
      i prezime.</div></td>
      </tr>
      <tr>
      <td>Vasa email adresa:</td>
      <td><p>
      <input name="email" type="text" size="41">
      </p>
      <div id="s2" style="display: none; color:#FF0000 ">Upisite svoju pravu
      email adresu. </div></td>
      </tr>
      <tr>
      <td>Broj telefona ili mobitela:</td>
      <td><p>
      <input name="mob" type="text" id="mob2" size="41">
      </p>
      <div id="s3" style=" color:#FF0000; display:none ">Upisite vas broj
      telefona ili mobitela. </div></td>
      </tr>
      <tr>
      <td>Poduzece: </td>
      <td><p>
      <input name="firma" type="text" id="firma" size="41">
      </p>
      <p style=" color:#FF0000; display:none ">Skojom firmom kontaktiramo
      </p></td>
      </tr>
      <tr>
      <td>Kako zelite da vas kontaktiramo:</td>
      <td><p>
      <select name="izbornik" >
      <option>= Odaberite =</option>
      <option value="Telefono m_ili mobitelom">Tel. / Mob.</option>
      <option value="Emailom" >Emailom</option>
      </select>
      </p>
      <div id="s4" style="display: none; color:#FF0000 ">Kako da vas
      kontaktiramo? </div></td>
      </tr>
      <tr>
      <td height="43">Vas a poruka:</td>
      <td height="43"><te xtarea rows="5" cols="37" name="poruka"[color=blue]
      ></textarea></td>[/color]
      </tr>
      <tr>
      <td colspan="2" align="center"> <input name="submit" type="submit"
      value="Salji!" onClick="provje ra(s1, s3, s2, s3, s4); return false;"></td>
      </tr>

      </table>
      </form>

      Script:
      <script language="JavaS cript" type="text/JavaScript">
      <!--
      function provjera(s1, s2, s3, s4) {
      var ime1 = document.formul ar.ime; //
      var email1 = document.formul ar.email;
      var mob1 = document.formul ar.mob;
      var izbornik1 = document.formul ar.izbornik;
      var obj1 = document.getEle mentById("s1");
      var obj2 = document.getEle mentById("s2");
      var obj3 = document.getEle mentById("s3");
      var obj4 = document.getEle mentById("s4");

      if (ime1.value.ind exOf(" ") == -1) {
      obj1.style.disp lay = "block";
      ime1.focus();
      }
      else obj1.style.disp lay = "none";
      if ((email1.value. indexOf("@") == -1) || (email1.value.i ndexOf(".") == -1))
      {
      obj2.style.disp lay = "block";
      email1.focus();
      }
      else obj2.style.disp lay = "none";
      if (mob1.length == 0) {
      obj3.style.disp lay = "block";
      mob1.focus();
      }
      else obj3.style.disp lay = "none";
      if (izbornik1.sele ctedIndex == 0) {
      obj4.style.disp lay = "block";
      izbornik1.focus ();
      } else {
      obj4.style.disp lay = "none";
      document.formul ar.submit(); // Kaze da u ovom redu nesto ne valja
      }
      }
      //-->
      </script>
      "Mikhail Esteves" <mikster@gmail. com> wrote in message
      news:1126693672 .875324.115060@ g14g2000cwa.goo glegroups.com.. .[color=blue]
      > kec wrote:[color=green]
      >> I want to create a script that prevent users of my form for typeing
      >> stupid
      >> things.[/color]
      >
      > What kind of input are you trying to validate? If its only to block
      > weird characters from an ordinary textbox, why not use a Regular
      > Expression instead?
      >
      > function IsLegal(str){
      > // Checks for @ ( ) < > [ ] , ; : \ / "
      > var badchars = /[\@\(\)\<\>\,\;\ :\\\/\"\[\]]/
      > if (str.match(badc hars))
      > return false;
      > else
      > return true;
      > }
      >
      > if (!IsLegal(Form. TextBox.Text))
      > {
      > alert("Illegal characters in TextBox. Please try again!");
      > }
      >
      > HTH.
      >
      > Mikhail
      >[/color]


      Comment

      • mike

        #4
        Re: Form problem??

        Mikhail,

        Your "badchars" are:

        [ @ ( ) < > , ; : \ / " ]

        Is that right?

        Comment

        Working...