Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Unhappy :: problems with a validation script ::

    ok, im working on something more powerful but i cant get the basics even working

    Code:
    function validateText() {
    
    d=document.forms[0];
    txtmsg='Please fill out all text fields marked * - thankyou';
    var textval = new Array('text1', 'text2');
    
      for (var i=0; i<textval.length; i++);
      if(d.elements[textval].value!='') {alert(txtmsg); d.text2val.focus(); return false};
      else alert('worked for ' + textval + '!');
    }
    i just cant see why the above shouldnt work - unless im being a total sausage! TIA!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    d.elements[textval].value --> d.elements[textval[i]].value
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    i get a

    'd.elements[...].value' is not an object
    any ideas?
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Not without seeing a more complete code, no.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Code:
    <HTML>
    <HEAD>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <title>:: validations ::</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <SCRIPT LANGUAGE="JavaScript">
    function validateText() {
    
    d=document.forms[0];
    txtmsg='Please fill out all text fields marked * - thankyou';
    var textval = new Array('text1', 'text2');
    
      for (var i=0; i<textval.length; i++);
      if(d.elements[textval[i]].value!='') {
      alert(txtmsg);} 
      //d.elements[textval[i]].focus(); return false};
      //else alert('worked for ' + textval[i] + '!');
    }
    
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM METHOD=post NAME="_vacancyApplicationForm2">
    <p>select1
        <SELECT NAME="select1" CLASS="vacancyfield" id="select1">
          <OPTION>**Please choose **
          <OPTION>Building Magazine
          <OPTION>Construction News
          <OPTION>Contract Journal
          <OPTION>Employee referral
          <OPTION>Speculative web search
          <OPTION>Other (see below)
        </SELECT>
    </p>
    <p>select2 
      <SELECT NAME="select2" CLASS="vacancyfield" id="select2">
        <OPTION>**Please choose **
        <OPTION>Building Magazine
        <OPTION>Construction News
        <OPTION>Contract Journal
        <OPTION>Employee referral
        <OPTION>Speculative web search
        <OPTION>Other (see below)
      </SELECT>
    </p>
    <p>text1 
      <INPUT NAME="text1" VALUE="" CLASS="vacancyfield" type="text">
    </p>
    <p>
      text2 
        <INPUT NAME="text2" VALUE="" CLASS="vacancyfield" type="text"> 
    </p>
    <p>radio1 
      <INPUT TYPE=radio NAME="radio1" VALUE="Yes" CLASS="vacancyradio">
      Yes
      <INPUT TYPE=radio NAME="radio1" VALUE="No" CLASS="vacancyradio">
      No</p>
    <p>radio2 
      <INPUT TYPE=radio NAME="radio2" VALUE="Yes" CLASS="vacancyradio">
    Yes
    <INPUT TYPE=radio NAME="radio2" VALUE="No" CLASS="vacancyradio">
    No</p>
    <p>
      <INPUT TYPE=button VALUE="Submit"onClick="validateText()">
      </p>
    </FORM>
    </BODY>
    </HTML>
    i know im using upppercase too... there is a reason but i cant be bothered to explain the final one wont!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Remove the semicolon.

    for (var i=0; i<textval.length; i++);

    But what kind of validation are you trying to do? You're alerting the message if the field is not empty.

    if(d.elements[textval[i]].value!='') {
    alert(txtmsg);}

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    ahhh - well, thats what i get trying to work in 35oC and no air conditioning i suppose!.... after those changes it still doesnt work tho...

    Code:
    <HTML>
    <HEAD>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <title>:: validations ::</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <SCRIPT LANGUAGE="JavaScript">
    function validateText() {
    
    d=document.forms[0];
    txtmsg='Please fill out all text fields marked * - thankyou';
    var textval = new Array('text1', 'text2');
    
      for (var i=0; i<textval.length; i++)
      if(d.elements[textval[i]].value='') {
      alert(txtmsg); d.elements[textval[i]].focus(); return false};
      else alert('worked for ' + textval[i] + '!');
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM METHOD=post NAME="_vacancyApplicationForm2">
    <p>select1
        <SELECT NAME="select1" CLASS="vacancyfield" id="select1">
          <OPTION>**Please choose **
          <OPTION>Building Magazine
          <OPTION>Construction News
          <OPTION>Contract Journal
          <OPTION>Employee referral
          <OPTION>Speculative web search
          <OPTION>Other (see below)
        </SELECT>
    </p>
    <p>select2 
      <SELECT NAME="select2" CLASS="vacancyfield" id="select2">
        <OPTION>**Please choose **
        <OPTION>Building Magazine
        <OPTION>Construction News
        <OPTION>Contract Journal
        <OPTION>Employee referral
        <OPTION>Speculative web search
        <OPTION>Other (see below)
      </SELECT>
    </p>
    <p>text1 
      <INPUT NAME="text1" VALUE="" CLASS="vacancyfield" type="text">
    </p>
    <p>
      text2 
        <INPUT NAME="text2" VALUE="" CLASS="vacancyfield" type="text"> 
    </p>
    <p>radio1 
      <INPUT TYPE=radio NAME="radio1" VALUE="Yes" CLASS="vacancyradio">
      Yes
      <INPUT TYPE=radio NAME="radio1" VALUE="No" CLASS="vacancyradio">
      No</p>
    <p>radio2 
      <INPUT TYPE=radio NAME="radio2" VALUE="Yes" CLASS="vacancyradio">
    Yes
    <INPUT TYPE=radio NAME="radio2" VALUE="No" CLASS="vacancyradio">
    No</p>
    <p>
      <INPUT TYPE=button VALUE="Submit"onClick="validateText()">
      </p>
    </FORM>
    </BODY>
    </HTML>
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Get some air outside.

    if(d.elements[textval[i]].value=='') {

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    OMG - man how do ppl in hot countries cope?!?! my brain is totally fried and its not even got near the hottest part of the day!

    thx guys - sorry for being such a sausage!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    It's hot here in the Philippines, but I'm used to it.

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    i live in england - nuff said
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •