troubleshooting Question

validating dynamic form objects

Avatar of woleraymond
woleraymond asked on
JavaScriptPHPWeb Applications
3 Comments1 Solution262 ViewsLast Modified:
i have form objects listed with the following for loop but the javascript doesnt validate if 2 items are listed.
pls help
<form name="form1" method="post" action="done.php">
  <table width="388"  border="0" cellspacing="5" cellpadding="0">
for ($i=1; $i<=$idv; $i++)
      <td width="115">Item Category </td>
      <td width="258"><select name="itemcat<? echo($i);?>">
         <option selected value="">Select One</option>
        <option value="Celtel100">Celtel (100)</option>
                                <option value="celtel200">Celtel (200)</option>
                                <option value="celtel300">Celtel (300)</option>
                                <option value="celtel400">Celtel (400)</option>
                                <option value="celtel500">Celtel (500)</option>                              
      <input name="datecreated<? echo($i)?>" type="hidden" id="datecreated" value="<? echo(date("Y-m-d"))?>">
      <input name="idv" type="hidden" id="idv" value="<? echo($idv);?>"></td>
      <td>Serial Number </td>
      <td><input name="S_no<? echo($i)?>" type="text" size="40" maxlength="40"></td>
      <td>Pin Number </td>
      <td><input name="P_no<? echo($i)?>" type="text" size="40" maxlength="40"></td>
      <td>Expiry Date </td>
      <td><input name="e_date<? echo($i)?>" type="text" id="e_date<? echo($i)?>">
      <td><?php  }?></td>
      <td><input type="submit" name="Submit" value="Add Item(s)" onClick = "return frmValidation(this)"></td>

function frmValidation(obj){
      var frm = obj.form;
        var idvv = document.form1.idv.value;
      var val = frm.idv.value;
   for (var x = 1; x <= idvv; x++)
   var vas = 'document.form1.itemcat'+x+'.value';
   var varw = 'document.form1.itemcat'+x;
   var datecreated = 'document.form1.datecreated'+x+'.value';
   var datecreatedw = 'document.form1.datecreated'+x;
   var S_no = 'document.form1.S_no'+x+'.value';
   var S_now = 'document.form1.S_no'+x;
   var P_no = 'document.form1.P_no'+x+'.value';
   var P_now = 'document.form1.P_no'+x;
   var e_date = 'document.form1.e_date'+x+'.value';
   var e_datew = 'document.form1.e_date'+x;
   var vas = eval(vas);
    var varw = eval(varw);
       var datecreated = eval(datecreated);
    var datecreatedw = eval(datecreatedw);
       var S_no = eval(S_no);
    var S_now = eval(S_now);
       var P_no = eval(P_no);
    var P_now = eval(P_now);
       var e_date = eval(e_date);
    var e_datew = eval(e_datew);
        alert("Please enter Item Category.");
            // "";
        return false;

        alert("Please enter Serial Number.");
            S_now.value= "";
        return false;
        alert("Please enter Pin Number.");
            P_now.value= "";
        return false;
        alert("Please enter Pin Number.");
            e_datew.value= "";
        return false;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros