[Skip to main content](#vessel-content)

#   Can Characteristic Selection trigger a javascript?

##

- **[icomex](/forum/user/4967-icomex "View icomex's Profile")**
- [![icomex's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4967.png)](/forum/user/4967-icomex "View icomex's Profile") Topic Author
- [ Offline](/forum/user/4967-icomex)

Less More

- Posts: 149
- Thank you received: 6
-
-

10 years 2 months ago [\#249640](#249640) by [icomex](/forum/user/4967-icomex "View icomex's Profile")  *[Can Characteristic Selection trigger a javascript?](/forum/31-development/886379-can-characteristic-selection-trigger-a-javascript#249640 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.2 -- PHP version -- : 5.6.16  I have Product which is made of three selected Option items within a packaging container (a Characteristic item which does not modify the price). The Customer normally selects which &quot;Color&quot; of container the product will use and then chooses the three component Options (each of which modifies the Product's price). After this, the Customer can select optional &quot;Artwork&quot; (a Custom Field also attached to this Product, which does not modify the price). My customer does maintain a stock of each container &quot;Color&quot;, and would like to use HikaShop to keep track of them.  The difficulty is that not all &quot;Artwork&quot; is available for use on both &quot;Colors&quot; of container. I currently have a javascript snippet included in the custom &quot;Artwork&quot; field's definition which builds the option list based upon which &quot;Color&quot; Characteristic is currently selected. This works for a normal purchase until a customer decides to modify their &quot;Color&quot; Characteristic after they have selected &quot;Artwork&quot;. I need to unselect the &quot;Artwork&quot; selection every time the &quot;Color&quot; Characteristic is modified.  I have examined HikaShop's editable Views and have not found a way to add an &quot;onChange&quot; attribute to the Characteristic drop-down input item, or to the &quot;Add To Cart&quot; button. It also appears that Custom Fields can only be attached to Product items, not Characteristic Items so I cannot provide different lists of &quot;Artwork&quot; to each Characteristic.  The javascript would be relatively simple if I could find the right place to add a trigger.  Do you have any suggestions?")* was created by *[icomex](/forum/user/4967-icomex "View icomex's Profile")*

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.2
-- PHP version -- : 5.6.16

I have Product which is made of three selected Option items within a packaging container (a Characteristic item which does not modify the price). The Customer normally selects which "Color" of container the product will use and then chooses the three component Options (each of which modifies the Product's price). After this, the Customer can select optional "Artwork" (a Custom Field also attached to this Product, which does not modify the price). My customer does maintain a stock of each container "Color", and would like to use HikaShop to keep track of them.

The difficulty is that not all "Artwork" is available for use on both "Colors" of container. I currently have a javascript snippet included in the custom "Artwork" field's definition which builds the option list based upon which "Color" Characteristic is currently selected. This works for a normal purchase until a customer decides to modify their "Color" Characteristic *after* they have selected "Artwork". I need to unselect the "Artwork" selection every time the "Color" Characteristic is modified.

I have examined HikaShop's editable Views and have not found a way to add an "onChange" attribute to the Characteristic drop-down input item, or to the "Add To Cart" button. It also appears that Custom Fields can only be attached to Product items, not Characteristic Items so I cannot provide different lists of "Artwork" to each Characteristic.

The javascript would be relatively simple if I could find the right place to add a trigger.

Do you have any suggestions?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4NjM3OS1jYW4tY2hhcmFjdGVyaXN0aWMtc2VsZWN0aW9uLXRyaWdnZXItYS1qYXZhc2NyaXB0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

10 years 2 months ago [\#249679](#249679) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Can Characteristic Selection trigger a javascript?](/forum/31-development/886379-can-characteristic-selection-trigger-a-javascript#249679 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.2 -- PHP version -- : 5.6.16  I have Product which is made of three selected Option items within a packaging container (a Characteristic item which does not modify the price). The Customer normally selects which &quot;Color&quot; of container the product will use and then chooses the three component Options (each of which modifies the Product's price). After this, the Customer can select optional &quot;Artwork&quot; (a Custom Field also attached to this Product, which does not modify the price). My customer does maintain a stock of each container &quot;Color&quot;, and would like to use HikaShop to keep track of them.  The difficulty is that not all &quot;Artwork&quot; is available for use on both &quot;Colors&quot; of container. I currently have a javascript snippet included in the custom &quot;Artwork&quot; field's definition which builds the option list based upon which &quot;Color&quot; Characteristic is currently selected. This works for a normal purchase until a customer decides to modify their &quot;Color&quot; Characteristic after they have selected &quot;Artwork&quot;. I need to unselect the &quot;Artwork&quot; selection every time the &quot;Color&quot; Characteristic is modified.  I have examined HikaShop's editable Views and have not found a way to add an &quot;onChange&quot; attribute to the Characteristic drop-down input item, or to the &quot;Add To Cart&quot; button. It also appears that Custom Fields can only be attached to Product items, not Characteristic Items so I cannot provide different lists of &quot;Artwork&quot; to each Characteristic.  The javascript would be relatively simple if I could find the right place to add a trigger.  Do you have any suggestions?")*

Hi,

You should be able to easily add an onchange to a characteristic or a onclick on the add to cart button.
For the characteristic dropdown, edit the file "show_block_characteristic" via the menu Display&gt;Views and change the line: Code:

echo $this-&gt;characteristic-&gt;displayFE($this-&gt;element, $this-&gt;params) . '&lt;/div&gt;';

to: Code:

echo str_replace('onchange="','onchange="callToMyCustomJavascriptFunction();',$this-&gt;characteristic-&gt;displayFE($this-&gt;element, $this-&gt;params)) . '&lt;/div&gt;';

For the add to cart, you can edit the file "quantity" of the view "product" and change the line: Code:

$this-&gt;ajax = 'return hikashopModifyQuantity(\''.$this-&gt;row-&gt;product_id.'\',field,1,0,\'cart\','.$module_id.')';

to:
Code:

$this-&gt;ajax = 'callToMySecondCustomJavascriptFunction();return hikashopModifyQuantity(\''.$this-&gt;row-&gt;product_id.'\',field,1,0,\'cart\','.$module_id.')';

The following user(s) said Thank You: [icomex](/forum/user/4967-icomex "View icomex's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4NjM3OS1jYW4tY2hhcmFjdGVyaXN0aWMtc2VsZWN0aW9uLXRyaWdnZXItYS1qYXZhc2NyaXB0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[icomex](/forum/user/4967-icomex "View icomex's Profile")**
- [![icomex's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4967.png)](/forum/user/4967-icomex "View icomex's Profile") Topic Author
- [ Offline](/forum/user/4967-icomex)

Less More

- Posts: 149
- Thank you received: 6
-
-

10 years 2 months ago [\#249735](#249735) by [icomex](/forum/user/4967-icomex "View icomex's Profile")  Replied by *[icomex](/forum/user/4967-icomex "View icomex's Profile")* on topic *[Can Characteristic Selection trigger a javascript?](/forum/31-development/886379-can-characteristic-selection-trigger-a-javascript#249735 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.2 -- PHP version -- : 5.6.16  I have Product which is made of three selected Option items within a packaging container (a Characteristic item which does not modify the price). The Customer normally selects which &quot;Color&quot; of container the product will use and then chooses the three component Options (each of which modifies the Product's price). After this, the Customer can select optional &quot;Artwork&quot; (a Custom Field also attached to this Product, which does not modify the price). My customer does maintain a stock of each container &quot;Color&quot;, and would like to use HikaShop to keep track of them.  The difficulty is that not all &quot;Artwork&quot; is available for use on both &quot;Colors&quot; of container. I currently have a javascript snippet included in the custom &quot;Artwork&quot; field's definition which builds the option list based upon which &quot;Color&quot; Characteristic is currently selected. This works for a normal purchase until a customer decides to modify their &quot;Color&quot; Characteristic after they have selected &quot;Artwork&quot;. I need to unselect the &quot;Artwork&quot; selection every time the &quot;Color&quot; Characteristic is modified.  I have examined HikaShop's editable Views and have not found a way to add an &quot;onChange&quot; attribute to the Characteristic drop-down input item, or to the &quot;Add To Cart&quot; button. It also appears that Custom Fields can only be attached to Product items, not Characteristic Items so I cannot provide different lists of &quot;Artwork&quot; to each Characteristic.  The javascript would be relatively simple if I could find the right place to add a trigger.  Do you have any suggestions?")*

Your suggestions work beautifully. Thanks!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4NjM3OS1jYW4tY2hhcmFjdGVyaXN0aWMtc2VsZWN0aW9uLXRyaWdnZXItYS1qYXZhc2NyaXB0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.058 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
