...

View Full Version : need some more helpppp!!!



arcmax
05-25-2005, 09:01 AM
Hi,

Well I have this code..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
var noRows=0;

function addTextBox(select){
var ids = ['roomtype','datestart','dateend','rate'];
var container = document.getElementById('TextBoxes');
var nu = select.options[select.selectedIndex].value;
for(;nu--;noRows++){
for(var k=0,id; id=ids[k]; k++) container.appendChild(createTextBox(id+noRows));
container.appendChild(document.createElement('br'));
}
var oSel = document.createElement('select')
var sVal =['single','double','triple','quadruple'];
oSel.setAttribute('name','sel'+nu);
for(var i=0;i<sVal.length;i++){
var oOpt = document.createElement('option');
var oTxt = document.createTextNode(sVal[i]); oOpt.setAttribute('value',sVal[i]);
oOpt.appendChild(oTxt);
oSel.appendChild(oOpt);
}
container.appendChild(oSel); container.appendChild(document.createElement('br'));
}


function createTextBox(id)
{
var box = document.createElement('input');
box.type = 'text';
box.size = '15';
box.id = box.name = id;
return box;
}
</script></head>

<body>
<form name="form" action="index3.php" method="post">
<select name="AddTextBox" size="1" onchange="addTextBox(this);" >
<option value="0">Add row</option>
<option value="1">One Row</option>
<option value="2">Two Row</option>
<option value="3">Three Row</option>
<option value="4">Four Row</option>
</select>

<div id="TextBoxes" ></div>
<input type="submit">
<?

foreach ( $_POST as $fieldName => $fieldValue)
{
echo "Field Name: $fieldName, Field Value: $fieldValue<br>";
}
?>
</body>
</html>

Basically it generates a 4 text boxes (one row) and one drop down box if I choose add one row. But If I choose add 2 rows it genrates 8 text boxes and and only one drop down box. Where as I want it to generate a droop down box on every row added

2) When I submit only the first frop down box value is shown and no other drop down box value are shon.

Does any one know what i am doing wrong here ?

thanks
Apurva M

Kor
05-25-2005, 11:55 AM
Try:



function addTextBox(select){
var ids = ['roomtype','datestart','dateend','rate'];
var container = document.getElementById('TextBoxes');
var nu = select.options[select.selectedIndex].value;
for(;nu--;noRows++){
for(var k=0,id; id=ids[k]; k++) container.appendChild(createTextBox(id+noRows));
container.appendChild(document.createElement('br'));
var oSel = document.createElement('select')
var sVal =['single','double','triple','quadruple'];
oSel.setAttribute('name','sel'+nu+noRows);
for(var i=0;i<sVal.length;i++){
var oOpt = document.createElement('option');
var oTxt = document.createTextNode(sVal[i]); oOpt.setAttribute('value',sVal[i]);
oOpt.appendChild(oTxt);
oSel.appendChild(oOpt);
}
container.appendChild(oSel); container.appendChild(document.createElement('br'));
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum