X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Need help with options script (https://forum.x-cart.com/showthread.php?t=52875)

McPace 03-17-2010 06:58 PM

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 03-17-2010 07:22 PM

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 03-17-2010 07:44 PM

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 03-17-2010 07:57 PM

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 03-17-2010 08:20 PM

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 03-17-2010 08:28 PM

Re: Need help with options script
 
I'm just really annoyed at this point

McPace 03-17-2010 08:33 PM

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?


All times are GMT -8. The time now is 10:42 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.