If Select Option 2 is select do this, if 3 selected do this else nothing

Hey guys,

I have set up a the monogramming feature set up here https://tinyurl.com/y6waod2s8 (written by another developer)

When a customer selects “Initials” or “DOB” I need to show the next Option below it.

I have been advised that this is a php question from the Javascript forums.

Code in the twig template file

{% if options %}
              <div class="options {{ journal2.settings.get('product_page_options_push_classes') }}">
                <h3>{{ text_option }}</h3>
                {% for option in options %}
                  {% if option.type == 'select' %}
                    <div class="option form-group{% if option.required %} required {% endif %} option-{{ option.type }}">
                      <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                      <select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
                        <option value="">{{ text_select }}</option>
                        {% for option_value in option.product_option_value %}
                          <option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
                            {% if option_value.price %}
                              ({{ option_value.price_prefix }}{{ option_value.price }})
                            {% endif %} </option>
                        {% endfor %}
                      </select>
                    </div>
                  {% endif %}

I tried doing it in JQuery but this is as far as I got

$(".option-date").hide();
$(".option-text").hide();

$(function() {
  $('.option-select').change(function(){
    $('.option-date').hide();
    $('.option-text' + $(this).val()).show();
  });
});

Referred to PHP thread from original JS thread here JS Noob, what's the best way to achieve this?

I think the point that Paul was making here is that first of all, forget about the screen display. Let the users do what they want, fill in any boxes they want, but have the back-end PHP when they click the “submit” button check and ignore those extra fields if they haven’t selected “DOB” or “Monogramming” options from the drop-down.

If those options vary from product to product, then you need to have some standardised way of deciding whether they are appropriate or not, and that will help you decide (a) whether to display the extra text boxes and (b) whether to process the data in the back end.

Once you have that decided, you can then maybe provide those flags into your front-end code, and figure out a way to use it to decide whether to show the boxes to be filled in. But first, handle it in the back end so if they fill out a box but haven’t selected the option, then it’s either flagged as an error or just silently dropped. Or even added on and highlighted - “you entered some initials, so we’ve added the surcharge for printing those, click here to remove”.

2 Likes

Ok that makes sense

Think this will be easier https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=13882

Looks like its what Im after

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.