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

Need help with options script

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-17-2010, 06:58 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Unhappy Need help with options script

I'm using a validation script, and need some help. I have framed artwork, 7 sizes, 5 frame options. Howver the smallest size doesn't come framed. So I need to check they've picked a size, and a frame, unless the size they picked was the first option, then a frame isn't required. Here's what I've messed with so far

Code:
if (document.getElementById('po1701').selectedIndex == 0) { alert('Please select an art size.'); return false; } if (document.getElementById('po1701').selectedIndex == 1 & document.getElementById('po1746').selectedIndex != 0 ) { alert('The smallest size of this image does not come framed, please un-select a frame option and try again. See our FAQ page for more information.'); return false; } if (document.getElementById('po1701').selectedIndex == 1 & document.getElementById('po1746').selectedIndex == 0 ) { return true; } else if (document.getElementById('po1746').selectedIndex == 0) { alert('Please select a frame style for your item.'); return false; } else return true;
__________________
McPace
4.1.12
Reply With Quote
  #2  
Old 03-17-2010, 07:22 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Angry Re: Need help with options script

OK I think the problem is in checking two elements in one if statement, b/c if I start with

Code:
if (document.getElementById('po1701').selectedIndex == 0) { alert('Please select the size of your artwork.'); return false; } if (document.getElementById('po1746').selectedIndex == 0) { alert('Please select a frame style for your artwork.'); return false; } else return true;

They both work fine.
Now if I add the two variable if statement it doesn't add to cart, the function works, but it never adds to cart.

Code:
if (document.getElementById('po1701').selectedIndex == 0) { alert('Please select the size of your artwork.'); return false; } if (document.getElementById('po1701').selectedIndex == 1 && document.getElementById('po1746').selectedIndex != 0 ) { alert('The smallest size of this image does not come framed, please un-select a frame option and try again. See our FAQ page for more information.'); return false; } if (document.getElementById('po1746').selectedIndex == 0) { alert('Please select a frame style for your artwork.'); return false; } else return true;

I'm gonna have to figure out what's up since I want two statements that check multiple values
__________________
McPace
4.1.12
Reply With Quote
  #3  
Old 03-17-2010, 07:44 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Exclamation Re: Need help with options script

I got rid of that return true inside the if, I don't get it, it all seems to work, but the product doesn't add to cart, the page just reloads with ?&err=options in the URL

currently using:

Code:
if (document.getElementById('po1701').selectedIndex == 0) { alert('Please select the size of your artwork.'); return false; } if (document.getElementById('po1701').selectedIndex == 1 && document.getElementById('po1746').selectedIndex != 0 ) { alert('The smallest size of this image does not come framed, please un-select a frame option and try again. See our FAQ page for more information.'); return false; } if (document.getElementById('po1746').selectedIndex == 0 && document.getElementById('po1701').selectedIndex != 1 ) { alert('Please select a frame style for your artwork.'); return false; } else return true;
__________________
McPace
4.1.12
Reply With Quote
  #4  
Old 03-17-2010, 07:57 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Default Re: Need help with options script

Seriously! I just tried pasting the code onto another product and each product has a different class id!? There has to be a better way to do this validation!?
__________________
McPace
4.1.12
Reply With Quote
  #5  
Old 03-17-2010, 08:20 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Question Re: Need help with options script

Ahh OK now I get it, it is working. But when it returns true, there is no product variant that matches that... so it can't add a product to the cart. Hmmm what to do now?
__________________
McPace
4.1.12
Reply With Quote
  #6  
Old 03-17-2010, 08:28 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Default Re: Need help with options script

I'm just really annoyed at this point
__________________
McPace
4.1.12
Reply With Quote
  #7  
Old 03-17-2010, 08:33 PM
  McPace's Avatar 
McPace McPace is offline
 

Member
  
Join Date: Sep 2008
Posts: 26
 

Thumbs up Re: Need help with options script

OH FOR THE LOVE!
If I put in this code:
Code:
if (document.getElementById('po1701').selectedIndex == 0) { alert('Please select the size of your artwork.'); return false; } if (document.getElementById('po1701').selectedIndex == 1 && document.getElementById('po1746').selectedIndex != 0 ) { alert('The smallest size of this image does not come framed, please un-select a frame option and try again. See our FAQ page for more information.'); return false; } if (document.getElementById('po1746').selectedIndex == 0 && document.getElementById('po1701').selectedIndex != 1 ) { alert('Please select a frame style for your artwork.'); return false; } else return true;

And have product variants that say select art size, select frame style, then it works perfectly.

So does anyone know how I can take this and apply it universally without using a specific products poID?
__________________
McPace
4.1.12
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 03:54 PM.

   

 
X-Cart forums © 2001-2020