www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to display a formvalidation() error in a table cell?

  1. #1
    Join Date
    Jan 2014
    Posts
    7

    How to display a formvalidation() error in a table cell?

    Hi list,

    I am looking for a long time now about writing the error the formvalidation script founds in the form which consists of table.

    For example if userid or group (first td) id emty (td2) I woul like to display 'Error: empty' in the third td.

    I googled around but could not find a way to do it and alert() is ugly and unclear because I have a lot of validations to do

    Could somebody help?

    It would greatly appreciated.

    j@n


    The HTML is quite simple:

    <form name="RACF-Access" onsubmit="Validateform()">
    <table border=1">
    <colgroup>
    <col width="15">
    <col width="*44">
    <col width="156">
    </colgroup>
    <tr>
    <th>Description</th>
    <th>Data</th>
    <th>Information</th>
    </tr>
    <tr>
    <td>Userid or group</td>
    <td><input type="text" size="8" name="userid"></td>
    <td type="text" id="e_id"></td>
    <tr>
    <td>Autority</td>
    <td><select name="authority">
    <option value="CHECK">CHECK</option>
    <option value="READ">READ</option>
    <option value="UPDATE">UPDATE</option>
    <option value="CONTROL">CONTROL</option>
    <option value="ALTER">ALTER</option>
    <option value="EXECUTE">EXECUTE</option>
    </select>
    </td>
    <td><DIV name="a_autr"</DIV</td>
    </tr>
    <tr>
    <td>Class</td>
    <td><input type="text" size="8" name="class"></td>
    <td><DIV name=e_class"</DIV</td>
    </tr>
    <tr>
    <td>Resource</td>
    <td><input type="text" size="44" name="resource"></td>
    <td><DIV name=e_resource</DIV</td>
    </tr>
    </table>
    <p><img src="./images/jan Einst.Neubauten.jpg" alt="Einst. Neubauten" widtr="159" height="156" align="middle"/></p>
    <input type="submit" value="Check Access">
    </form>

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,653
    1 use the [code]code goes here[/code] for posting your code
    2 try this:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>123</title>
    <script>
    function valf(frm){
    var elems=frm.elements,
        len=elems.length,
    	skipped='submit,reset',
    	isvalid=true;
    if(!valf.ret){valf.ret={};}
    for(var i=0; i < len; i++){
    if(skipped.indexOf(elems[i].type) !=-1){continue;}
    else{
    var td=document.getElementsByName(elems[i].name)[0].parentNode.parentNode.cells[2];
    td.style.color='#fff';
    td.style.textAlign='center';
    td.style.fontWeight='bold';
    /*
    the code below checks only for empty values,
    so change the condition according to your needs
    */
    if(!elems[i].value){
    td.innerHTML='<--  can not be empty';
    td.style.backgroundColor='Crimson';
    valf.ret[elems[i].name]=false;
    }
    else{
    td.innerHTML='OK';
    td.style.backgroundColor='Green';
    if(valf.ret[elems[i].name] != null){delete(valf.ret[elems[i].name]);}
    }
    }
    }
    for(var k in valf.ret){if(k){isvalid=valf.ret[k]};}
    return isvalid;
    }
    </script>
    </head>
    <body>
    <form name="RACF-Access" id="RACF-Access" onsubmit="return valf(this)">
     <table border="1">
     <colgroup>
     <col width="15">
     <col width="*44">
     <col width="156">
     </colgroup>
     <tr>
     <th>Description</th>
     <th>Data</th>
     <th>Information</th>
     </tr>
    <tr>
    <td>Userid or group</td>
    <td><input type="text" size="8" name="userid" /></td>
    <td></td>
    </tr>
     <tr>
     <td>Autority</td>
     <td><select name="authority">
     <option value="">Select one</option>
     <option value="CHECK">CHECK</option>
     <option value="READ">READ</option>
     <option value="UPDATE">UPDATE</option>
     <option value="CONTROL">CONTROL</option>
     <option value="ALTER">ALTER</option>
     <option value="EXECUTE">EXECUTE</option>
     </select>
     </td>
     <td></td>
     </tr>
     <tr>
     <td>Class</td>
     <td><input type="text" size="8" name="class" /></td>
     <td></td>
     </tr>
     <tr>
     <td>Resource</td>
     <td><input type="text" size="44" name="resource" /></td>
     <td></td>
     </tr>
     </table>
     <p><img src="./images/jan Einst.Neubauten.jpg" alt="Einst. Neubauten" width="159" height="156" align="middle" /></p>
     <input type="submit" value="Check Access" />
     </form>
    </body>
    </html>

  3. #3
    Join Date
    Jan 2014
    Posts
    7
    Thank you very very much. I was amazed but it worked first time.
    j@n

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,653
    you're welcome, greetings from Russia ))

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles