Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Javascript Validation for Product Options

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-23-2007, 03:51 AM
  scoobie's Avatar 
scoobie scoobie is offline
 

Advanced Member
  
Join Date: Dec 2006
Location: Sydney
Posts: 84
 

Default Javascript Validation for Product Options

Hi Guys,

I applied the select XXX product options dropdown change from mffowler but this simple change isn't working for me. I am getting a javascript error that I am having trouble solving. I get the following error in Firefox:- document.getElementById("29") has no properties.

In Explorer I get object required on line 155. I found line 155 to be this <!--

Can someone see what I am doing wrong? I have attached a screen dump of the product options page in my admin. This js error prevents the product from being selected.
Attached Thumbnails
Click image for larger version

Name:	prod_options_validation.jpg
Views:	269
Size:	49.5 KB
ID:	593  
__________________
X-CART 4.1.8 (Add-Ons: onSale, CDSEO, AOM, Thickbox)
PHP 4.4.4
SQL 4.1.21
Linux O/S
Reply With Quote
  #2  
Old 10-23-2007, 04:00 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: Javascript Validation for Product Options

For 4.1.x, try this:

[edited] File: /skin1/modules/Product_Options/customer_options.tpl

FIND

Code:
{foreach from=$v.options item=o} <option value="{$o.optionid}"{if $o.selected eq 'Y'} selected="selected"{/if}>{$o.option_name}{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0} ({if $o.modifier_type ne '%'}{include file="currency.tpl" value=$o.price_modifier display_sign=1 plain_text_message=1}{else}{$o.price_modifier}%{/if}){/if}</option>{/foreach}

REPLACE WITH:

Code:
<option>Please Select Your {$v.classtext|default:$v.class}...{if $o.selected eq 'Y'} selected="selected"{/if}</option> {foreach from=$v.options item=o} <option value="{$o.optionid}">{$o.option_name}{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0} ({if $o.modifier_type ne '%'}{include file="currency.tpl" value=$o.price_modifier display_sign=1 plain_text_message=1}{else}{$o.price_modifier}%{/if}){/if}</option> {/foreach}

THEN -- in the product options javascript, use something like this:

Code:
if (document.getElementById('po17').selectedIndex == 0) { alert('Please select...'); return false; } if (document.getElementById('po18').selectedIndex == 0) { alert('Please select...'); return false; } else return true;

and of course, change the 'po' in the js to the actual product option number.
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #3  
Old 10-23-2007, 04:36 AM
  scoobie's Avatar 
scoobie scoobie is offline
 

Advanced Member
  
Join Date: Dec 2006
Location: Sydney
Posts: 84
 

Default Re: Javascript Validation for Product Options

Carp,

My product.options.tpl looks like this. Is this the right code I need to replace (maybe just the first <td>?

{foreach from=$v.options item=o}
<tr>
<td>{if $o.avail ne 'Y'}<font color="red">{/if}{$o.option_name}{if $o.avail ne 'Y'}</font>{/if}</td>
{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0}
<td>{$o.price_modifier|formatprice}</td>
<td>{if $o.modifier_type|default:"$" eq '$'}{$config.General.currency_symbol}{else}%{/if}</td>
{/if}
</tr>
{foreachelse}
<tr>
{if $geid ne ''}<td>&nbsp;</td>{/if}
<td colspan="{if $v.is_modifier eq 'Y'}3{else}1{/if}">{$lng.lbl_options_list_empty}</td>
</tr>
{/foreach}</table>
</td>
</tr>
{foreachelse}
<tr>
{if $geid ne ''}<td width="15" class="TableSubHead">&nbsp;</td>{/if}
<td align="center" colspan="7">{$lng.lbl_product_options_list_empty}< /td>
</tr>
{/foreach}
__________________
X-CART 4.1.8 (Add-Ons: onSale, CDSEO, AOM, Thickbox)
PHP 4.4.4
SQL 4.1.21
Linux O/S
Reply With Quote
  #4  
Old 10-23-2007, 04:40 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: Javascript Validation for Product Options

SOrry -- should have been more clear.. I update the previous post. Edit File: /skin1/modules/Product_Options/customer_options.tpl
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #5  
Old 10-23-2007, 05:04 AM
  scoobie's Avatar 
scoobie scoobie is offline
 

Advanced Member
  
Join Date: Dec 2006
Location: Sydney
Posts: 84
 

Default Re: Javascript Validation for Product Options

I thought it didn't look right. Once I changed the right template everything looks sweet as. Thanks Carp. I can go to sleep now.
__________________
X-CART 4.1.8 (Add-Ons: onSale, CDSEO, AOM, Thickbox)
PHP 4.4.4
SQL 4.1.21
Linux O/S
Reply With Quote
  #6  
Old 10-23-2007, 03:02 PM
 
TL408 TL408 is offline
 

X-Adept
  
Join Date: Jan 2005
Posts: 549
 

Default Re: Javascript Validation for Product Options

Hi Carpeperdiem,

I notice in the "Validation Javascript" below, you have two production option lines listed. If my item have only one product option group, should I remove the second line? Or change the production option to the same PO number on both lines?

For example, in one of my item with only 1 product option and the product option number is 500. Should I have the "Validation Javascript" to look like this instead?

--------------------------------------------------------------------------------------------------------------------------
if (document.getElementById('po500').selectedIndex == 0)
{ alert('Please select a size for your item.'); return false;
}
else return true;
--------------------------------------------------------------------------------------------------------------------------

Thank you
-Tuan



Quote:
Originally Posted by carpeperdiem
THEN -- in the product options javascript, use something like this:

Code:
if (document.getElementById('po17').selectedIndex == 0) { alert('Please select...'); return false; } if (document.getElementById('po18').selectedIndex == 0) { alert('Please select...'); return false; } else return true;

and of course, change the 'po' in the js to the actual product option number.
__________________
Win2003 IIS6, PHP 5.2.3, MySQL 5.0.45 and X-Cart 4.1.9
Reply With Quote
  #7  
Old 10-23-2007, 03:21 PM
 
TL408 TL408 is offline
 

X-Adept
  
Join Date: Jan 2005
Posts: 549
 

Default Re: Javascript Validation for Product Options

OK.....I think I got it "half-way" working. (Would that be the same as not working? lol....)

I have the "skin1\modules\Product_Options\customer_options.tp l" file revised with the codes above and "Validation Javascript" added to the product option. I went to the product details page and click "Add to Cart", I would get the "Please make a selection" pop-up message window. So this part is working as expected.

And here is the part that isn't working....I went ahead and select one of the available product option listed and the clicked "Add to Cart". It took me to the "Your Shopping Cart" page with an empty cart instead of adding that item with the selection option.

Maybe I've been staring that the monitors for too long and overlooked something. Here is the "Validation Javascript" used

----------------------------------------------------------------------------------------------------------------------------
if (document.getElementById('po630').selectedIndex == 0)
{ alert('Please make a selection.'); return false;
}
else return true;
----------------------------------------------------------------------------------------------------------------------------


And here is my "skin1\modules\Product_Options\customer_options.tp l" file
----------------------------------------------------------------------------------------------------------------------------
{* $Id: customer_options.tpl,v 1.24 2006/04/07 05:19:21 svowl Exp $ *}
{if $product_options ne ''}
{if $nojs ne 'Y'}
<tr style="display: none;"><td>
<script type="text/javascript" language="JavaScript 1.2">
<!--
var alert_msg = '{$alert_msg}';
-->
</script>
{include file="modules/Product_Options/check_options.tpl"}
</td></tr>
{/if}

{foreach from=$product_options item=v}
{if $v.options ne '' || $v.is_modifier eq 'T'}
<tr>
<td valign="middle" height="25">{if $usertype eq "A"}{$v.class}{else}{$v.classtext|default:$v.class }{/if}</td>
<td valign="middle">
{if $cname ne ""}
{assign var="poname" value="$cname[`$v.classid`]"}
{else}
{assign var="poname" value="product_options[`$v.classid`]"}
{/if}
{if $v.is_modifier eq 'T'}
<input id="po{$v.classid}" type="text" name="{$poname}" value="{$v.default|escape}" />
{else}
<select id="po{$v.classid}" name="{$poname}"{if $disable} disabled="disabled"{/if}{if $nojs ne 'Y'} onchange="javascript: check_options();"{/if}>
{*
{foreach from=$v.options item=o}
<option value="{$o.optionid}"{if $o.selected eq 'Y'} selected="selected"{/if}>{$o.option_name}{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0} ({if $o.modifier_type ne '%'}{include file="currency.tpl" value=$o.price_modifier display_sign=1 plain_text_message=1}{else}{$o.price_modifier}%{/if}){/if}</option>
{/foreach}
*}

<option>Please Select Your {$v.classtext|default:$v.class}...{if $o.selected eq 'Y'} selected="selected"{/if}</option>
{foreach from=$v.options item=o}
<option value="{$o.optionid}">{$o.option_name}{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0} ({if $o.modifier_type ne '%'}{include file="currency.tpl" value=$o.price_modifier display_sign=1 plain_text_message=1}{else}{$o.price_modifier}%{/if}){/if}</option>
{/foreach}

</select>
{/if}
</td>
</tr>
{/if}
{/foreach}
{/if}


{if $product_options_ex ne ""}
<tr>
<td colspan="2"><font id="exception_msg" color="red"></font></td>
</tr>
{if $err ne ''}
<tr>
<td colspan="2"><font class="CustomerMessage">{$lng.txt_product_options_ combinations_warn}:</font></td>
</tr>
{foreach from=$product_options_ex item=v}
<tr>
<td>{foreach from=$v item=o}{if $usertype eq "A"}{$o.class}{else}{$o.classtext}{/if}: {$o.option_name}<br />{/foreach}<br /></td>
</tr>
{/foreach}
{/if}
{/if}
----------------------------------------------------------------------------------------------------------------------------
__________________
Win2003 IIS6, PHP 5.2.3, MySQL 5.0.45 and X-Cart 4.1.9
Reply With Quote
  #8  
Old 10-23-2007, 07:37 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: Javascript Validation for Product Options

looks correct. should work.
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #9  
Old 10-23-2007, 07:40 PM
 
TL408 TL408 is offline
 

X-Adept
  
Join Date: Jan 2005
Posts: 549
 

Default Re: Javascript Validation for Product Options

Quote:
Originally Posted by carpeperdiem
looks correct. should work.
Hmmm.....I'm running version 4.1.9. Not sure if that would make a difference. Have you tried this on version 4.1.9 yet? Maybe I should test it on a 4.1.8 installation and see.

Thanks
-Tuan
__________________
Win2003 IIS6, PHP 5.2.3, MySQL 5.0.45 and X-Cart 4.1.9
Reply With Quote
  #10  
Old 10-24-2007, 04:55 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: Javascript Validation for Product Options

Quote:
Have you tried this on version 4.1.9 yet?

yes. works fine. I'll PM you a link to show you on my test server.
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:45 PM.

   

 
X-Cart forums © 2001-2020