/    Sign up×
Community /Pin to ProfileBookmark

Hello evrybody…anyone can help me to solve my problem???This is my javascript to insert the new row.The problem is…. it will clone all my fields such as amount_perunit,quantity,and amount. so i cannot insert the new input in that fields.For example if i have already key in the input in the first row and then when I want to insert the new row….it will display the data that I just key-in in the first row.

<script type=”text/javascript”>
var limit=10;
function addRow(Frm){
var allRows = document.getElementById(‘tab’).getElementsByTagName(‘tr’);
if(allRows.length<=limit){
var lastRow = allRows[allRows.length-1];
var root = lastRow.parentNode;
[B]var newRow = root.appendChild(lastRow.cloneNode(true));
var numRow = newRow.length;
Frm.elements[‘amaun_seunit’][allRows.length – 2].value=””;
Frm.elements[‘quantity’][allRows.length – 2].value=””;
Frm.elements[‘amount’][allRows.length – 2].value=””;
//alert(“NumRow : ” + allRows.length);[/B]

}
else {
alert(‘Rows limited to ‘+limit);
}
}

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMay 25.2005 — The problem is.... it will clone all my fields such as amount_perunit,quantity,and amount. so i cannot insert the new input in that fields.[/QUOTE]
Yes, the data in the field is part of the object that gets cloned. So what? You just have to programmatically clear these fields after they are added to the structure. What is the problem with that?
Copy linkTweet thisAlerts:
@shmunazauthorMay 26.2005 — but I dont know how to programmatically clear that field after added.

Frm.elements['amaun_seunit'][allRows.length - 2].value="";

Frm.elements['quantity'][allRows.length - 2].value="";

Frm.elements['amount'][allRows.length - 2].value="";

This script doesn't work bcoz when I want to add data in the field amount per unit, he field become empty.
Copy linkTweet thisAlerts:
@phpnoviceMay 26.2005 — Well, I tested the following with a table that had a column header row and it works just fine for clearing the new form fields:
<i>
</i>var rowLimit = 10;
function addTblRow(Frm) {
var allTblRows = document.getElementById('tab').getElementsByTagName('tr');
var lastTblRow = allTblRows.length - 1;
if (lastTblRow &lt; rowLimit) {
allTblRows[lastTblRow].parentNode.appendChild(allTblRows[lastTblRow].cloneNode(true));
Frm.elements['T1'][lastTblRow].value = "";
Frm.elements['T2'][lastTblRow].value = "";
Frm.elements['T3'][lastTblRow].value = "";
} else {
alert('Rows limited to ' + rowLimit);
}
return true;
}
×

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 5.15,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...