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)
-   -   Make Text Option a Required Field (https://forum.x-cart.com/showthread.php?t=13737)

tabasco-addict 04-30-2005 08:25 AM

Make Text Option a Required Field
 
I have added a text box in my product options. I need to make the customer type something in the box before it's added to the cart.

In other words, we cannot process the order if the text box is blank for that product.

Thanks

tabasco-addict 05-03-2005 06:43 AM

My own answer
 
So anyway, after no resopnses on the board I tried a million combinations of validation script until something worked.

Heres what I came up with so someone else doesn't have to go through the monkey business that I had to.

Code:

if (document.getElementById('po42').value == "")
{alert('Please enter the name of the person or company the the software will be registered in.')
document.getElementById('po42').focus()
return false;
}
else {
return true;
}


Just replace po42 with po and the index of your product option.

Replace the alert with whatever you would like to say.

leorulz 12-08-2007 10:25 PM

Re: Make Text Option a Required Field
 
where do i insert this code?

fotodog13 11-07-2008 05:30 AM

Re: Make Text Option a Required Field
 
Thanks for posting this Tabasco addict
It works like a charm. ( using 4.1.11)
I had been screwing around with the same problem for the last hour or so before I found your code.

leorulz if you are still wondering where to put this code it goes in the product options section.
When you are adding product options to your product at the bottom of the page you will see a box titled
Validation script ( Javascript)
put it there.

best

Scott V
fotodog13
4.1.11 gold
apache

Warwick 11-18-2009 07:42 AM

Re: Make Text Option a Required Field
 
something else that seems to work (4.2.x)
Code:

if (product_option('Name of your text option').value == '')
{ alert('Alert you want to show');
return false;
}
else return true;


Yalokin 03-23-2010 11:39 AM

Re: Make Text Option a Required Field
 
Ok, Thank you.

I did somethink like this before:

var obj = product_option("Line1"); if(obj.value.length<1) { alert("'Line1' Length is '"+obj.value.length+"' Text Lines fields can not be empty''"); obj.focus(); return false; } return true;

But we have hundreds of products what might require same validation of more then in text line.
Some thing like: Line1, Line2, Line3...

In additon if you try to add our product to shopping cart and them edit (in cart.php) page x-cart open pop-up and above validation script not working.

Did anyone tried it before in cart.php page.

thank you.


Quote:

Originally Posted by Warwick
something else that seems to work (4.2.x)
Code:

if (product_option('Name of your text option').value == '')
{ alert('Alert you want to show');
return false;
}
else return true;



dmpinder 05-24-2010 08:06 AM

Re: Make Text Option a Required Field
 
Thanks for posting tobasco-addict, very useful code!

Darren

jeff@purelyproven.com 03-08-2012 12:37 PM

Re: Make Text Option a Required Field
 
Anyone know how to show the required text field on the category product list? Even with validation on the field working properly, customers can add products without completing the text field as long as they don't go to the actual product page. Any solution or ideas would be appreciated!

P.S. How do I change my display name to something OTHER than my personal e-mail =\


All times are GMT -8. The time now is 11:25 PM.

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