I have a form and I want to give an add more item link to add three textboxes.User can add upto 7 times. that means user can input 7 items at one time.
the second one is I want to insert these 7 items into mysql tables in separate rows. How can I do it.
<form name="frmaddservice" action="" method="post" class="jNice" onsubmit="return checkaddservice();">
<p><label>Customer Name:</label><input name="txtcustname" type="text" class="text-long" /></p>
<p><label>Customer Phone:</label><input name="txtcustphone" type="text" class="text-long" /></p>
<p><label>Customer Email:</label><input name="txtcustemail" type="text" class="text-long" /></p>
<div id="fieldset">
<p><label>Item Type:</label>
<select name="seltype">
<option>Select Type</option>
<?php
while($rowitem = mysql_fetch_assoc($seltype))
{
?>
<option><?php echo $rowitem['item_name']; ?></option>
<?php
}
?>
</select>
</p>
<p><label>Item Brand</label><input name="txtitembrand" type="text" class="text-long"></textarea></p>
<p><label>Item Quantity:</label><input name="txtqty" type="text" class="text-long" /></p>
<p><label>Item Description</label><textarea name="txtdesc"></textarea></p>
<p><label>Item Warranty Date:</label><input name="txtdate" type="text" class="text-long" />
<script language="JavaScript">
new tcal ({
// form name
'formname': 'frmaddservice',
// input name
'controlname': 'txtdate'
});
</script>
</p>
<input type="submit" value="Add Service"/>
</div>
</form>
I have uploaded the file here, please take a look.
Validation code
<SCRIPT TYPE="TEXT/JAVASCRIPT">function IsNumeric(strString)
{
var strValidChars = "0123456789";
var strChar;
var blnResult = true;
if (strString.length == 0) return false;
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}function checkaddservice(){
with (window.document)
{
if(frmaddservice.txtcustname.value == "")
{
alert("Please enter Customer's Name.");
frmaddservice.txtcustname.focus();
return false;
}
if(frmaddservice.txtcustphone.value == "")
{
alert("Please enter Customer's phone.");
frmaddservice.txtcustphone.focus();
return false;
}
if(IsNumeric(frmaddservice.txtcustphone.value) == "false")
{
alert("Please enter Valid phone.");
frmaddservice.txtcustphone.focus();
return false;
}
for(var i=0; i<7; i++)
{
if(frmaddservice.elements["seltype" + i].value == "Select Type")
{
alert("Please Select Item Type!");
return false;
}
if(frmaddservice.elements["txtqty" + i].value == "")
{
alert("Please Enter Item Quantity!");
return false;
}
var qty = frmaddservice.elements["txtqty" + i].value;
if(IsNumeric(qty) == "false")
{
alert("Please Enter Valid Quantity!");
frmaddservice.elements["txtqty" + i].focus();
return false;
}
}
}}</SCRIPT>