1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Validation of the columns and rows in javascript

Discussion in 'JavaScript' started by lavanya74, Sep 14, 2009.

  1. #1
    Hi,

    I nedd a Validation of the columns and rows in javascript .
    I have two textboxes as Year and No.
    I have to do a validation on based on the year and number combination.
    which i have done but this validation has to be done for all the rows.
    first the year should be selected and checked whether it is equal to 1982 then it should read coloumn respective to it.
    llr it should read for 2 nd row year field the number value...soon.
    Please help....need urgently this code.... :(
     
    lavanya74, Sep 14, 2009 IP
  2. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    >>i have done but this validation has to be done for all the rows
    If you have done it for one, why not repeat it for the rest?
    Post the current code; you will get better replies.

    This JavaScript Form Validation script might be useful.
     
    prasanthmj, Sep 14, 2009 IP
  3. mad_gundam

    mad_gundam Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well you can assign all the fields with same class nam and then loop through all the input fields and validate them
     
    mad_gundam, Sep 14, 2009 IP
  4. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this sample code, i think it helps you:

    <head>
      <script>
        function CheckAndSubmit () {
          var table = document.getElementById ("myTable");
          var inputs = table.getElementsByTagName ("input");
    
          for (var i = 0; i < inputs.length; i+=2) {
            var yearInput = inputs[i];
            var numberInput = inputs[i+1];
    
            if (yearInput.value == "1982") {
              if (numberInput.value > 10) {
                alert ("Invalid number in the " + (i/2 + 1) + ". row!");
                return false;
              }
            }
          }
    
          return true;
        }
      </script>
    </head>
    <body>
      <form method="post" action="#URL#" onsubmit="return CheckAndSubmit ()">
        <table id="myTable">
          <tr>
            <td>Year: <input type="text" value="1985" /></td>
            <td>Number: <input type="text" value="5" /></td>
          </tr>
          <tr>
            <td>Year: <input type="text" value="1982" /></td>
            <td>Number: <input type="text" value="9" /></td>
          </tr>
          <tr>
            <td>Year: <input type="text" value="1982" /></td>
            <td>Number: <input type="text" value="11" /></td>
          </tr>
        </table>
        <input type="submit" value="Send" />
      </form>
    </body>
    Code (markup):
    For further details, visit the following sites:
    onsubmit event, getElementsByTagName method, table object.
     
    gumape, Sep 15, 2009 IP
  5. lavanya74

    lavanya74 Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thks for the reply the code is working for the html which u have send .but
    var inputs = table.getElementsByTagName ("input");

    my textfield value is a struts 2 input which will be declared with the <s:textfields> tag how to use this tag in the getElementsByTagName ?

    and my table alery have a class="xyz" which is the CSS so unable to use both css and Id in table tag i.e.
    <table id="mytable" class="xyz">.. so pls. help :)
     
    lavanya74, Sep 16, 2009 IP