User Name Password Register
DaniWeb IT Discussion Community
All
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 373,476 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 3,971 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: 2081 | Replies: 3 | Solved
Reply
Join Date: Dec 2007
Posts: 3
Reputation: nicolechuah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nicolechuah nicolechuah is offline Offline
Newbie Poster

Help Cant get the cell values,please help,thanks.

  #1  
Dec 30th, 2007
<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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 23
Reputation: chrelad is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
chrelad's Avatar
chrelad chrelad is offline Offline
Newbie Poster

Solution Re: Cant get the cell values,please help,thanks.

  #2  
Jan 1st, 2008
Hi nicolechuah,

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
Reply With Quote  
Join Date: Dec 2007
Posts: 3
Reputation: nicolechuah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nicolechuah nicolechuah is offline Offline
Newbie Poster

Re: Cant get the cell values,please help,thanks.

  #3  
Jan 2nd, 2008
em~ still cant calculate/total up the values.....

But,anyways,thanks you,chrelad. [img]http://www.daniweb.com/forums/dani-images/smilies/sleek/qqb014.gif[/img]
Last edited by nicolechuah : Jan 2nd, 2008 at 10:04 am.
Reply With Quote  
Join Date: Dec 2007
Posts: 3
Reputation: nicolechuah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nicolechuah nicolechuah is offline Offline
Newbie Poster

Re: Cant get the cell values,please help,thanks.

  #4  
Jan 3rd, 2008
i already solved the problem,thanks for all.[img]http://www.daniweb.com/forums/dani-images/smilies/sleek/qqb014.gif[/img]
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 5:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC