Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

error in javascript function to update a price field


PerrySmit

Recommended Posts

I have added two fields filed into the products table named "products.pricemodifier" and "products.listprice"

 

Idea is to have some different calculation methods which I want show while user change the fields in the product edit layout, without the need of refeshing the window.

 

To start somewhere, I have added the following function into spiffCalv2_1.js like

 

function calculateprice(){

alert ("you have changed the price!!!")

}

 

and in the category.pho I have added the option'onChange="calculateprice()

 

So far so good, the alert will come up as soon I change the products.pricemodifier field.

 

Now I want set the products_price field based on the change you made in the products_pricemodifier field

.

To start simple, I suppose the function should sound like:

 

function calculateprice(){

this.products_price.value=123

}

 

But will not work...What goes wrong in my function?

 

Thanks for any help,

Perry

Link to comment
Share on other sites

you need to pass the object to the function i.e.

 

'onChange="calculateprice( this )"

 

and the function

 

function calculateprice( myObject )

{

myObject.products_price.value=123;



}

Link to comment
Share on other sites

unfortunantly still no luck,

 

To summurize

The lines in

admin/categories.php

is

tep_draw_input_field('products_pricemodifier', $pInfo->products_pricemodifier,'onChange="calculateprice( this )"');

 

and in spiffycal.js I have

 

function calculateprice( myObject ){

myObject.products_price.value=123;

}

 

Maybe more to think off?

 

 

 

and the function

 

function calculateprice( myObject )

{

myObject.products_price.value=123;



}

Link to comment
Share on other sites

you need the field name to be the same in the function as it is in the input box

 

i.e.

 

you have called the input field products_pricemodifier and then referred to it as products_price in the function.

 

They have to be the same.

 

I would suggest getting it working outside of oscommerce first - just make a quick form in ordinary html.

Link to comment
Share on other sites

sorry I told you the wrong thing then ....

 

the function does not need the name as you are passing the object.

 

function calculateprice( myObject ){ 

myObject.value="123"; 

}

 

you just need to reference the value directly

Link to comment
Share on other sites

Thanks for your help,

 

though still can?t accomplish my wish.

 

I want up date an other field when a onChange is on products_pricemodifier.

 

So, how to pointer to an other field I want change...

 

 

 

 

sorry I told you the wrong thing then ....

 

the function does not need the name as you are passing the object.

 

function calculateprice( myObject ){ 

myObject.value="123"; 

}

 

you just need to reference the value directly

Link to comment
Share on other sites

you should look at the javascript reference manual really.

 

But ...

 

if your form was called "example_form" and you had a field called field1 and another called field2

 

you can put the onchange in field1 and reference field2 with document.example_form.field2.value="123"

 

so you wouldnt need to pass the object in the function as you are referencing it directly.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...