Current location: Hot Scripts Forums » General Web Coding » JavaScript » Quantity counter


Quantity counter

Reply
  #1 (permalink)  
Old 07-17-09, 10:41 AM
Gaug Gaug is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Quantity counter

Hello.

I have this code in a cycle that runs for a certain number of times:

PHP Code:

<input name="nombre[<?php echo $z;?>]" type="text" value="0.00" onkeyup="total.value = <?php echo $monto;?> - this.value."/>
What I am trying to do is, in the variable '$monto' I have a number, then every time you go for the cycle, let's say three times in the text box that is up, I will put up numbers, let's say '$monto= $ 15,000' and the three text boxes that will be created, will have these values 10000, 1000 and 1500.

I have another box:

PHP Code:

<input type="text" name="total" id="total" value="" disabled
I assumed, or what I had planned was taking into account what I put before, you should see '2500' on the box 'total', as subtracting 10000, 1000 and 1500 to 15000 is'2500,' but nothing happens . Any idea what might I be doing wrong?

Thanks in advance.

Greetings.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-17-09, 11:54 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
Hmmm. Your a little vague here. Well actually your a ton vague and your providing only the minimal code.
First of this is PHP code, your asking for help in a JavaScript form.

Second off the second code box is not PHP or JavaScript, it is HTML

That being said if your trying to subtract a value from the variable $monto then just subtract it like this:

<?php
$monto=$monto-1000;
?>

if your trying to display the variable in the second code box change that line to this:

<input type="text" name="total" id="total" value="<?php echo $monto; ?>">
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-18-09, 06:23 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Code:
total.value = <?php echo $monto;?> - this.value.
Change total.value. to total.value;, or better yet:

Code:
document.getElementById('total').value=<?php echo $monto;?>-this.value
You might want to post a bit more code to make it easier to understand.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-20-09, 09:28 AM
Gaug Gaug is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
First of all, thanks for replying.

I know I posted PHP and HTML code, but it was neccesary for you to understand what I'm looking for.

As I said before the first text box belongs to a 'for' cycle, like this:

PHP Code:

<?php
for($q=$mes;$q<=$mes_ini2;$q++) {  ?>
        
        <td><input name="nombre[<?php echo $z;?>]" type="text" value="0.00" id="valor"  onkeyup="document.getElementById('total').value=<?php echo $monto;?>-this.value"  /></td>
        <?php
        
}
                
?>
So it doesn't make a certain quantity of boxes, that could be the problem but I don't know much about javascript.

I tried what you told me, wirehopper, but it doesn't seem to work alright, maybe because what I just said, hope you or someone else can help me out.

Thanks in advance.

EDIT: I tried to make a function in JavaScript, something like this:
Code:
function restar() {
    for (var i=0; i<cajas.length; i++) {
        cajas[i] = document.getElementById('valor'+i).value;
        monto -= cajas[i];
		
    }
        document.getElementById('total').value = monto;
}
But in the textbox where it should show the amount left, it just shows the value of '$monto' and it doesn't substract, doesn't matter what I write in the boxes that belong to the 'for' cycle.

Hope it's easier for you to help me with this function.

Greetings.

Last edited by Gaug; 07-20-09 at 09:51 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI Counter Help moreofahtmlguy Perl 3 06-03-09 08:35 AM
hit counter for embedded video cedric813 Script Requests 1 07-01-07 05:43 AM
simple counter Lunar Script Requests 1 11-28-06 04:07 AM
Counter script (to offer free counter service) basara55 Script Requests 0 06-29-04 09:48 PM
PHP counter rogue_the_one PHP 3 02-26-04 01:15 PM


All times are GMT -5. The time now is 12:48 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.