•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 361,619 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,211 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1956 | Replies: 3 | Solved
![]() |
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
<html>
<head>
<script type="text/javascript">
function insRow()
{
var x=document.getElementById('myTable').insertRow(1);
var y=x.insertCell(0);
var a=x.insertCell(1);
var b=x.insertCell(2);
var d= '<input type="button" value="Delete" onclick="deleteRow(this)">';
var e= '<input type="text" id="answer" />';
var f= '<input type="text" name=num; id="answer1" />';
y.innerHTML=e;
a.innerHTML=f;
b.innerHTML=d;
}
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
function check(browser,browser1)
{
document.getElementById("answer").value=browser;
document.getElementById("answer1").value=browser1;
}
function this_total( for_what )
{
var total = 0;
var i;
for (i = 1;i<10;i++){
var this_col = for_what.parentElement.parentElement.colIndex;
var num = this_col.getElementsById("answer1")[i].value;
total += num;
}
for_what.getElementById("ans").value = total;
return;
}
</script>
</head>
<body>
<p>What's your favorite browser?</p>
<form>
<input type="radio" name="browser" onclick="insRow();check(this.value1,this.value2)" value1="Burger" value2="5.00">Burger<br />
<input type="radio" name="browser" onclick="insRow();check(this.value,this.value2)" value="Fried Rice" value2="4.00">Fried Rice<br />
<input type="radio" name="browser" onclick="insRow();check(this.value,this.value2)" value="Nescafe" value2="2.50">Nescafe<br />
<input type="radio" name="browser" onclick="insRow();check(this.value,this.value2)" value="Orange Juice" value2="3.60">Orange Juice<br />
<br />
</form>
<table id="myTable" border="1">
<tr>
<td>Title</td>
<td>Price</td>
<td>Cancel</td>
</tr>
<tr>
<td>Total: </td>
<td><input type="text" name="total" id="ans"></td>
<td><input type="button" onClick="this_total( this )" value="calculate"></td>
</tr>
</table>
<br />
</body>
</html>
This is a simple meal order selection.When i click on the radio button,it will insert a new row to a table and insert the value. And there also got delete button to delete each row.
After finish order,i need to total up the prices.But,when i click on the calculate button, it shown error on page.How can i get the values and total up all the values?
Please take a look and help me ,thanks.
<head>
<script type="text/javascript">
function insRow()
{
var x=document.getElementById('myTable').insertRow(1);
var y=x.insertCell(0);
var a=x.insertCell(1);
var b=x.insertCell(2);
var d= '<input type="button" value="Delete" onclick="deleteRow(this)">';
var e= '<input type="text" id="answer" />';
var f= '<input type="text" name=num; id="answer1" />';
y.innerHTML=e;
a.innerHTML=f;
b.innerHTML=d;
}
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
function check(browser,browser1)
{
document.getElementById("answer").value=browser;
document.getElementById("answer1").value=browser1;
}
function this_total( for_what )
{
var total = 0;
var i;
for (i = 1;i<10;i++){
var this_col = for_what.parentElement.parentElement.colIndex;
var num = this_col.getElementsById("answer1")[i].value;
total += num;
}
for_what.getElementById("ans").value = total;
return;
}
</script>
</head>
<body>
<p>What's your favorite browser?</p>
<form>
<input type="radio" name="browser" onclick="insRow();check(this.value1,this.value2)" value1="Burger" value2="5.00">Burger<br />
<input type="radio" name="browser" onclick="insRow();check(this.value,this.value2)" value="Fried Rice" value2="4.00">Fried Rice<br />
<input type="radio" name="browser" onclick="insRow();check(this.value,this.value2)" value="Nescafe" value2="2.50">Nescafe<br />
<input type="radio" name="browser" onclick="insRow();check(this.value,this.value2)" value="Orange Juice" value2="3.60">Orange Juice<br />
<br />
</form>
<table id="myTable" border="1">
<tr>
<td>Title</td>
<td>Price</td>
<td>Cancel</td>
</tr>
<tr>
<td>Total: </td>
<td><input type="text" name="total" id="ans"></td>
<td><input type="button" onClick="this_total( this )" value="calculate"></td>
</tr>
</table>
<br />
</body>
</html>
This is a simple meal order selection.When i click on the radio button,it will insert a new row to a table and insert the value. And there also got delete button to delete each row.
After finish order,i need to total up the prices.But,when i click on the calculate button, it shown error on page.How can i get the values and total up all the values?
Please take a look and help me ,thanks.
Hi nicolechuah,
Try this out:
Hope this helps
Tested in IE and Firefox
Try this out:
<html>
<head>
<script type="text/javascript">
function insRow()
{
var x=document.getElementById('myTable').insertRow(1);
var y=x.insertCell(0);
var a=x.insertCell(1);
var b=x.insertCell(2);
var d= '<input type="button" value="Delete" onclick="deleteRow(this)">';
var e= '<input type="text" id="answer" />';
var f= '<input type="text" name=num; id="answer1" />';
y.innerHTML=e;
a.innerHTML=f;
b.innerHTML=d;
}
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
function check(el)
{
document.getElementById("answer").value=el.getAttribute('value1');
document.getElementById("answer1").value=el.getAttribute('value2');
}
function this_total( for_what )
{
var total = 0;
var i;
for (i = 1;i<10;i++){
var this_col = for_what.parentElement.parentElement.colIndex;
var num = this_col.getElementsById("answer1")[i].value;
total += num;
}
for_what.getElementById("ans").value = total;
return;
}
</script>
</head>
<body>
<p>What's your favorite browser?</p>
<form>
<input type="radio" name="browser" onClick="insRow();check(this)" value1="Burger" value2="5.00">Burger<br />
<input type="radio" name="browser" onClick="insRow();check(this)" value1="Fried Rice" value2="4.00">Fried Rice<br />
<input type="radio" name="browser" onClick="insRow();check(this)" value1="Nescafe" value2="2.50">Nescafe<br />
<input type="radio" name="browser" onClick="insRow();check(this)" value1="Orange Juice" value2="3.60">Orange Juice<br />
<br />
</form>
<table id="myTable" border="1">
<tr>
<td>Title</td>
<td>Price</td>
<td>Cancel</td>
</tr>
<tr>
<td>Total: </td>
<td><input type="text" name="total" id="ans"></td>
<td><input type="button" onClick="this_total( this )" value="calculate"></td>
</tr>
</table>
<br />
</body>
</html>Hope this helps
Tested in IE and Firefox ![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
ajax apple asp cell cell phones congress consumer cross-browser javascript menu with few lines of code deleting records from ms sql table where columns have duplicate values developer development email firefox home html internet iphone ipod javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator kernel keynote lg linux macworld microsoft mobile msdn office phone phones playstation prada prevent javascript menu from getting hidden under flash movies ps3 site software sql stocks technology termination fees touchscreen valentine's day video vista web 500
- Set datagridview cell values. (VB.NET)
- Getting Current Row Values in the DataGrid control (ASP.NET)
- how to read spread sheet in Python? (Python)
- how to place values into a gatagrid cell in vb.net (VB.NET)
- exporting Excel tables into PostgreSQL database (Python)
- passing values from a form to a dialog form (VB.NET)
- Need help diplaying null values (PHP)
- Single Table Cell background (HTML and CSS)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Obfuscating email addresses in HTML
- Next Thread: Javascript Function


Linear Mode