Forum Moderators: open

Message Too Old, No Replies

Dropbox+calculator

Javasript code

         

Vanchi

10:25 am on Mar 27, 2015 (gmt 0)

10+ Year Member



Hi im doing cloth business.

I want to fix dropbox calculator. for example a user click "silk" in dropbox and then enter the quantity he want get anwser.
I need like below

Dropbox(product)- Silk(Rate-19)
Number box(Quantity)- 10
Answer= 190.

I need full code this. Kindly help plz anybody.

engine

1:31 pm on Apr 2, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld. If you have some code you'd like us to evaluate, please paste it in the thread.

StupidScript

10:19 pm on Jun 2, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script type="text/javascript">
function checkTotal() {
qty = document.getElementById('quantity').value;
val = document.getElementById('dropbox')[document.getElementById('dropbox').selectedIndex].value;
var ttl = (qty * val);
alert(ttl);
}
</script>
Product: <select name=dropbox id=dropbox>
<option value=19>Silk</option>
<option value=20>Wool</option>
<option value=21>Cotton</option>
</script>
</select><br>
Quantity: <input type=text name=quantity id=quantity><br>
<button type=button onclick="checkTotal()">CHECK</button>

Lots of ways to do it ... that's one.

Vanchi

3:10 pm on Jun 3, 2015 (gmt 0)

10+ Year Member



Thanks but i need auto total instead of clicking check button

whitespace

3:19 pm on Jun 13, 2015 (gmt 0)

10+ Year Member Top Contributors Of The Month



...but i need auto total instead of clicking check button


Then attach the event to the onchange handler of the SELECT and INPUT controls as well.

"Dropbox" - I was thinking "cloud storage provider"!?

It's a "dropdown menu" or "select" box.

Gowri pandiyan

9:20 am on Jun 18, 2015 (gmt 0)

10+ Year Member



@Vanchi, Just wanted to share this code, You would have got it though.

<script type="text/javascript">
function checkTotal() {
qty = document.getElementById('quantity').value;
val = document.getElementById('dropbox')[document.getElementById('dropbox').selectedIndex].value;
var ttl = (qty * val);
//alert(ttl)
document.getElementById('total').value = ttl;
}
</script>
Product: <select name=dropbox id=dropbox >
<option value=19>Silk</option>
<option value=20>Wool</option>
<option value=21>Cotton</option>
</select><br>
Quantity: <input type=text name=quantity id=quantity onchange="checkTotal()"><br>
Total: <input type=text name=total disabled id=total>