Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...i want to append text boxes and apply validations to new textboxes also...I already designed that append program but comming to that validation i dont know how we apply validation.and this is my code...

HTML
<script type="text/javascript"><a href="">
$(function() {
var addDiv = $('#addinput');
var i = $('#addinput p').size() + 1;
$('#addNew').live('click', function() {
$('<p><input type="text" id="i" size="40" name="p_new_' + i +'" value="" placeholder="I am New" /><a href="#" id="remNew">Remove</a> 

</p>').appendTo(addDiv);
i++;
return false;
});
$('#remNew').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
</script>


how can i add validations to this new textboxes???
Posted
v2
Comments
SrikantSahu 1-Dec-14 8:29am    
Hi,
The validation code, is it a function? Also can you please attach your html file.
Thanks
Bhushan Patki 1-Dec-14 9:15am    
Did you get solution?

For Validations, just call one JavaScript function on some TextBox events like keyup or change etc...
JavaScript
$('<p><input type="text" onkeyup="ValidationFunction(this)" id="i" size="40" name="p_new_' + i +'" value="" placeholder="I am New" /><a href="#" id="remNew">Remove</a></p>').appendTo(addDiv);
 
Share this answer
 
v2
HTML
<html>
<head>

  <script language="javascript">
   function addRow(tableID) {

    var table = document.getElementById(tableID);

    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);

    var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "text";
    cell1.appendChild(element1);
 }
function validateAllInputBoxes(ffevent)
{
   var inputs = document.getElementsByTagName('input');
   for(var i = 0; i < inputs.length; ++i)
      if(inputs[i].type === 'text')
        
         if(inputs[i].value === '') 
         {
            alert("form could not be sent one input text field is empty");
            stopEvent(ffevent);
         }
}
   </script>
   </head>


   <body>


    <form onsubmit="validateAllInputBoxes(event);">
   <input type="button" value="Add textbox" onclick="addRow('dataTable')" />


    
         
          <input type="text" name="symp[]" /> 
         
       
    
   <input type="submit" value="Submit" name="ADD_SUBMIT">
   </input></form>


  </body>
</html>  
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900