Jump to content

$icount++ Dynamic creation of input boxes - store number of boxes


johnwayne77

Recommended Posts

i have this script:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<?
$icount = "0";

?>
<script type="text/javascript">


var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput() {

arrInput.push(arrInput.length);

arrInputValue.push("");
display();
}

function display() {
document.getElementById('parah').innerHTML="";
for (intI=0;intI<arrInput.length;intI++) {
document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
}
}

function saveValue(intId,strValue) {
arrInputValue[intId]=strValue;
}

function createInput(id,value) {
return "<? $icount++; ?><input type='text' id='perioada"+ id +"' name='perioada"+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>";
}
function deleteInput() {
if (arrInput.length > 0) {
arrInput.pop();
arrInputValue.pop();
}
display();
}

</script>

</HEAD>


<BODY>

<form name="myform" id="myform" method="get">
<p id="parah">Dynamic creation of input boxes</p>
<? echo $icount; ?>
<a href="javascript:addInput()">Add more input field(s)</a><br>
<a href="javascript:deleteInput()">Remove field(s)</a>


<table align="center" width="250">
<tr align="center">
<td align="right"><input type=submit value=SUBMIT name=submit class="buttons"></td>
</tr>
</table>
</form>
</body>
</html>

 

it generates input boxes for each click, which is good..

 

now, i need to fetch all the values, no matter how many boxes there are..

 

i want to retrieve the number of boxes so i thought of adding an incremented variable $icount++ in the function .. but it doesn't work..

 

any ideas how i can get this thing start?

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.