/    Sign up×
Community /Pin to ProfileBookmark

I have some problem with my coding. I have one row. The row have 2 drop down menu and 3 text field. The row can be added when I click the Add Row button. The data from drop down menu I retrieve from database. That mean I create the drop down menu using JavaScript. But the problem is, when the new row was insert, the drop down menu doesn’t work. It cannot retrieve the data from my database. My friend suggest that I declare the array at each drop down menu depend on the new row. But I don’t know how.Plz help me…. ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51May 19.2005 — Code? LInk?
Copy linkTweet thisAlerts:
@shmunazauthorMay 20.2005 — This my javascript for add new row

<script type="text/javascript">

var limit=10;

function addRow(){

var allRows = document.getElementById('tab').getElementsByTagName('tr');

if(allRows.length<=limit){

var lastRow = allRows[allRows.length-1];

var root = lastRow.parentNode;

var newRow = root.appendChild(lastRow.cloneNode(true));

}

else {

alert('Rows limited to '+limit);

}

}

And this one is my PHP coding to create the scroll down

<table id="tab" width="100%" border="1" cellspacing="1">

<tr bgcolor="#FFFFCC">

<td><div align="center"><strong>Kod Jabatan </strong></div></td>

<td><div align="center"><strong>Kod Vot </strong></div></td>

<td><div align="center"><strong>Amaun Seunit</strong></div></td>

<td><div align="center"><strong>Kuantiti</strong></div></td>

<td><div align="center"><strong>Jumlah</strong></div></td>

</tr>

<tr>

<td width="191"><select name="select" id="DeptList" onChange="biListJabatan(this,this.form)">

<option value="0">[Sila Pilih]</option>

<?php

$Result = &$biModel->biListJabatan();

while (!$Result->EOF){

?>
<option value="<?=trim($Result->fields['dept_no'])?>">
<?=$Result->fields['dept_no']?>

-

<?=$Result->fields['dept_name']?>

</option>

<?php

$Result->MoveNext();

}
?>
</select></td>
<td width="191">
<div align="center">
<script language="javascript" type="text/javascript">



function biListJabatan(Jabatan, Frm){

var ListBil = Frm.elements['kod_hasil'];

var which = Jabatan.selectedIndex-1;


for (i=ListBil.length; i>=0; i--){

ListBil.options[0] = null;

}

if ( which >= 0 ) {
ListBil.options[0] = new Option("[Sila Pilih]", "");

for (i=0; i<BilList[which].length; i++) {
ListBil.options[i+1] = new Option(BilList[which][i], BilList[which][i]);
}

ListBil.disabled = false;

}
else {
ListBil.disabled = true;
ListBil.options[0] = new Option(Blank, "");
ListBil.selectedIndex = 0;

}

if (ListBil.length <= 1){
for (i=ListBil.length; i>=0; i--){
ListBil.remove(i);
}
ListBil.disabled = true;
ListBil.options[0] = new Option("Tiada Pilihan Bil Untuk Jabatan Ini", "");
ListBil.selectedIndex = 0;

}

}

<?php

echo "var BilList = new Array (" .$Result->RecordCount().");n";

$Result->MoveFirst();

$num = 0;

while (!$Result->EOF) {

$Result3 = &$biModel->biListBil($Result->fields['dept_no']);
echo "BilList[".$num."] = new Array (";
if ($Result3){
while (!$Result3->EOF) {
echo """.trim($Result3->fields['kod_hasil'])." - ".$Result3->fields['notes'].""";
$Result3->MoveNext();
if (!$Result3->EOF) echo ",";
}
}
echo ");nn";
$num += 1;
$Result->MoveNext();
}
?>
</script>

<select name="kod_hasil" id="kod_hasil" onChange="biListKodVOT(this,this.form)">
<option value="0">[Sila Pilih]</option>
</select>
</div></td>

<td width="191"><input type="text" name="amount_unit" id="amount_unit" value="<?=$Result4->fields['amount_unit']?>"></td>
<td width="98"><div align="left"><input name="kuantiti" type="text">
</div></td>
<td width="98"><input type="text" name="jumlah" onBlur="jumlahNilai(this.value,this.form)"></td>
</tr>
</table>
Copy linkTweet thisAlerts:
@shmunazauthorMay 20.2005 — This my javascript for add new row

<script type="text/javascript">

var limit=10;

function addRow(){

var allRows = document.getElementById('tab').getElementsByTagName('tr');

if(allRows.length<=limit){

var lastRow = allRows[allRows.length-1];

var root = lastRow.parentNode;

var newRow = root.appendChild(lastRow.cloneNode(true));

}

else {

alert('Rows limited to '+limit);

}

}

And this one is my PHP coding to create the scroll down

<table id="tab" width="100%" border="1" cellspacing="1">

<tr bgcolor="#FFFFCC">

<td><div align="center"><strong>Kod Jabatan </strong></div></td>

<td><div align="center"><strong>Kod Vot </strong></div></td>

<td><div align="center"><strong>Amaun Seunit</strong></div></td>

<td><div align="center"><strong>Kuantiti</strong></div></td>

<td><div align="center"><strong>Jumlah</strong></div></td>

</tr>

<tr>

<td width="191"><select name="select" id="DeptList" onChange="biListJabatan(this,this.form)">

<option value="0">[Sila Pilih]</option>

<?php

$Result = &$biModel->biListJabatan();

while (!$Result->EOF){

?>
<option value="<?=trim($Result->fields['dept_no'])?>">
<?=$Result->fields['dept_no']?>

-

<?=$Result->fields['dept_name']?>

</option>

<?php

$Result->MoveNext();

}
?>
</select></td>
<td width="191">
<div align="center">
<script language="javascript" type="text/javascript">



function biListJabatan(Jabatan, Frm){

var ListBil = Frm.elements['kod_hasil'];

var which = Jabatan.selectedIndex-1;


for (i=ListBil.length; i>=0; i--){

ListBil.options[0] = null;

}

if ( which >= 0 ) {
ListBil.options[0] = new Option("[Sila Pilih]", "");

for (i=0; i<BilList[which].length; i++) {
ListBil.options[i+1] = new Option(BilList[which][i], BilList[which][i]);
}

ListBil.disabled = false;

}
else {
ListBil.disabled = true;
ListBil.options[0] = new Option(Blank, "");
ListBil.selectedIndex = 0;

}

if (ListBil.length <= 1){
for (i=ListBil.length; i>=0; i--){
ListBil.remove(i);
}
ListBil.disabled = true;
ListBil.options[0] = new Option("Tiada Pilihan Bil Untuk Jabatan Ini", "");
ListBil.selectedIndex = 0;

}

}

<?php

echo "var BilList = new Array (" .$Result->RecordCount().");n";

$Result->MoveFirst();

$num = 0;

while (!$Result->EOF) {

$Result3 = &$biModel->biListBil($Result->fields['dept_no']);
echo "BilList[".$num."] = new Array (";
if ($Result3){
while (!$Result3->EOF) {
echo """.trim($Result3->fields['kod_hasil'])." - ".$Result3->fields['notes'].""";
$Result3->MoveNext();
if (!$Result3->EOF) echo ",";
}
}
echo ");nn";
$num += 1;
$Result->MoveNext();
}
?>
</script>

<select name="kod_hasil" id="kod_hasil" onChange="biListKodVOT(this,this.form)">
<option value="0">[Sila Pilih]</option>
</select>
</div></td>

<td width="191"><input type="text" name="amount_unit" id="amount_unit" value="<?=$Result4->fields['amount_unit']?>"></td>
<td width="98"><div align="left"><input name="kuantiti" type="text">
</div></td>
<td width="98"><input type="text" name="jumlah" onBlur="jumlahNilai(this.value,this.form)"></td>
</tr>
</table>



And this script is the button that call he AddRow function

<tr bgcolor="#FFFFFF">

<td colspan="9"><table width="100%" border="0" cellspacing="0">

<tr>

<td width="80%"><input type="button" name="Button" value="Tambah Bil" onClick="addRow()"></td>

<td width="20%"><div align="right">

<input name="totalAmount" type="text" id="totalAmount">

</div></td>

</tr>

</table></td>

</tr>
×

Success!

Help @shmunaz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...