Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Mar 2009
    Posts
    40
    Plugin Contributions
    0

    Default Radio button requires text field

    I have a product with two options, both selected by a radio button. One of the options is for custom text to appear on the product. Is there a way that if a customer selects option 2 then the text becomes a required field. Or if they select option 1 then the text box can't be filled in?

  2. #2
    Join Date
    Dec 2009
    Posts
    55
    Plugin Contributions
    0

    Default Re: Radio button requires text field

    I too am looking for this feature. Has anyone figured this out?

  3. #3
    Join Date
    Mar 2009
    Posts
    40
    Plugin Contributions
    0

    Default Re: Radio button requires text field

    I worked this out using the add on Cross Validation

    http://www.zen-cart.com/index.php?ma...oducts_id=1507

    Its not as clean as I'd like, but it does the job.

  4. #4
    Join Date
    Dec 2009
    Posts
    55
    Plugin Contributions
    0

    Default Re: Radio button requires text field

    Thanks for the link!

    I actually figured this out just using some simple javascript. The file I edited was:

    Code:
     Rootofstore/includes/templates/YOURTEMPLATE/templates/"tpl_product_info_display.php".
    Keep in mind that this only works with products that have the specific attributes you have to check. In my case, I had a few text fields that needed to be filled ONLY if they checked a certain radio option above those fields.

    I added this to the bottom of the file:
    Code:
    <script language="JavaScript">
    	new validateForm(document.forms['cart_quantity']);
    </script>
    At the top of the file, I added the javascript needed to test the form. If you look at the source of your product page, you can find the "name" of the form element that you need to check. The things in red are the things you have to customize. Actually, the conditions themselves you should customize to how you need it:

    Code:
    <script language="JavaScript" type="text/javascript">
     function validateForm(oForm)
     {
     	//oForm refers to the form which you want to validate
     	oForm.onsubmit = function() // attach the function to onsubmit event
     	{
     		if(oForm.elements['attrib-16-107'].checked == false && oForm.elements['id[txt_14]'].value == '')
    		{
    			alert("Please enter a name for your Registrant.");
    			return false;
    		}
    		else if(oForm.elements['attrib-16-107'].checked == false  && oForm.elements['id[txt_15]'].value == '')
    		{
    			alert("Please enter an email for your Registrant.");
    			return false;
    		}
    		else if(oForm.elements['attrib-16-107'].checked == false && oForm.elements['id[txt_21]'].value == '')
    		{
    			alert("Please enter a phone number for your Registrant.");
    			return false;
    		}
    		else if(oForm.elements['attrib-16-107'].checked == false && oForm.elements['id[txt_17]'].value == '')
    		{
    			alert("Please enter a street address for your Registrant.");
    			return false;
    		}
    		else{
    			return true;	
    		}
     	}
     }
     </script>
    Hope this helps!

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Radio button requires text field

    Nice script, as long as the user has javascript enabled. I presume that if js is disabled, there will be no checking done and the user will be able to add any combination to their cart.

    Also, there is a recommended procedure for including javascript in pages without adding it directly to a PHP file - see the tutorials.

  6. #6
    Join Date
    Dec 2009
    Posts
    55
    Plugin Contributions
    0

    Default Re: Radio button requires text field

    Yes, there's that caveat. Though another feature on my site requires that as well, so I don't mind it.

    And do you have a link to said tutorial?
    Vu Nguyen | Multimedia Developer & Webmaster
    Robotics Academy/Robomatter
    Robomatter Robotics Education Store

  7. #7
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Radio button requires text field

    I guess the info is not in the tutorials. I found it in the wiki by searching for "javascript":
    http://www.zen-cart.com/wiki/index.p...s_-_Javascript

  8. #8
    Join Date
    Dec 2009
    Posts
    55
    Plugin Contributions
    0

    Default Re: Radio button requires text field

    Nice! Thanks for the link. This is the first time I've heard of this information and I searched a ton through the threads.
    Vu Nguyen | Multimedia Developer & Webmaster
    Robotics Academy/Robomatter
    Robomatter Robotics Education Store

  9. #9
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Radio button requires text field

    It has been mentioned and discussed numerous times in the forum... I guess you just didn't find the right threads.

  10. #10
    Join Date
    Dec 2009
    Posts
    55
    Plugin Contributions
    0

    Default Re: Radio button requires text field

    Possibly. I know I found about two dozen threads relating to "conditional attributes" that either had 0 replies or didn't have a solution, and about 2 that had a final reply with "I found a solution!" and never actually posted anything.
    Vu Nguyen | Multimedia Developer & Webmaster
    Robotics Academy/Robomatter
    Robomatter Robotics Education Store

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v154 State field requires an input when min value is 0
    By tk42one in forum General Questions
    Replies: 3
    Last Post: 27 Apr 2016, 02:26 AM
  2. How to align radio button and text?
    By Carolc in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 27 Mar 2011, 05:40 PM
  3. Radio Button or Larger text Link in Shopping Cart?
    By luxevintage in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 7 Sep 2008, 04:08 AM
  4. Search Header Button and Text Field
    By swelter83 in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 14 Mar 2008, 02:05 AM
  5. Payment Radio Button Text. How Do Ya Change It?
    By bumba000 in forum General Questions
    Replies: 5
    Last Post: 6 May 2007, 08:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR