Required field based on selection

This area is devoted to Magento Form Builder SmartFormer Gold. Please ask questions, report bugs and share ideas here.

Required field based on selection

Postby zak » Wed Nov 16, 2011 11:21 am

Hi,

I have one select field with values like: test1, test2, test3. If I select test3 new field should be required, but if I select any other value field should not be required. How can I achieve this. For better understanding please take a look at:
http://sonin.com/product-registration/ and select OTHER for Which model did you purchase? * you will see new field which should be required.

Best Regards
Zak
zak
 
Posts: 1
Joined: Wed Nov 16, 2011 11:16 am

Re: Required field based on selection

Postby Boneyard » Tue Jan 03, 2012 9:44 pm

Hi Zak. I have a question for you, I'm trying to accomplish the same thing here. I still have not been able to get the new field to appear, how did you accomplish this is you don't mind me asking?
Boneyard
 
Posts: 1
Joined: Tue Jan 03, 2012 9:39 pm

Re: Required field based on selection

Postby IToris team » Thu Jan 12, 2012 3:02 pm

Hello Boneyard and Zak,

Let say you have 2 elements on your form: select box with id=select_box and input box with id=my_input. Select box has the following select list:

Code: Select all
0|-- Please select --
1|Item 1
2|Item 2
3|Item 3


If the second item is selected (Item 2) then input box should be required.

Please open Tools - JS Editor and add the following code after document.getElementById('sfg_submitter').value = submitter;

Code: Select all
var my_select_box = document.getElementById('select_box');
   var my_input = document.getElementById('my_input');
   
   if (my_select_box && my_input && my_select_box.value == 2 && my_input.value == "") {
      alert('Please enter the value');
      my_input.focus();
      return;
   }


IToris Team
IToris team
Site Admin
 
Posts: 1355
Joined: Mon Jan 19, 2009 12:33 pm


Return to SmartFormer Gold for Magento

Who is online

Users browsing this forum: No registered users and 1 guest