Jump to content

Form total


Kano

Recommended Posts

Hi there,

I need help with this javascript because it does not work as far i can tell?

 

<SCRIPT>

function gettotals(obj, rowcnt){

var stot = 0;var temp = 0;var ff = 0;

for (var cnt = 1; cnt <= rowcnt; cnt++){

temp = (obj.form.getElementById("price_"+cnt).value) * (obj.form.getElementById("qty_"+cnt).value);

stot += temp;

}

ff = stot.toFixed(2);

obj.form.elements['s_total'].value = ff;

}

</SCRIPT>

<BODY>

....

<?php while(blarb){...

<input type = 'text' id = 'price_$rowcnt' name = 'price_$wsi_id' value = '$wsi_price' .....

<select id = 'qty_$rowcnt' name='qty_$wsi_id' .......

.....}

<input type="text" name="s_total".....

<input type='button' value = 'Get Totals' onclick='gettotals(this, \"$rowcnt\")' />

 

Thanks for any help..

 

Link to comment
Share on other sites

What are you doing with this line?

<input type='button' value = 'Get Totals' onclick='gettotals(this, \"$rowcnt\")' />

 

It appears that you are referencing a PHP variable from within javascript alone. That can't be done. You have to echo the PHP variable using PHP into the javascript position in which you wish it to be placed.

Link to comment
Share on other sites

Hi there,

Yes I forgot to include the php tags in the code i listed to save time.

 

So that is not the problem.

 

The code I listed is so that the form will get totals from all the item totals onclick in a for loop.

 

But like all Javascript it never seems to work properly.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.