Personalized checkout and custom promotions with Shopify Scripts
Hi,
On customer registration I have a customized "dropdown menu" to select his company name from a preexisted list name. I want that field to required to select from.
Also if he select "Other" from the dropdown menu, a new field appears and I need it "required" as well.
would appreciate any help,
code:
<div class="field">
<label for="CompanyName">Company</label>
<div class="select" >
<select id="CompanyName" name="customer[company]" >
<option value="NaN" >Your company...</option>
</select>
{% render 'icon-caret' %}
</div>
</div>
<div class="field hidden">
<input
type="text"
name="customer[company_other]"
id="CompanyName-Other"
placeholder="Company name"
>
<label for="CompanyName-Other">
Company name
</label>
</div>
Solved! Go to the solution
This is an accepted solution.
<div class="field">
<label for="CompanyName">Company</label>
<div class="select" >
<select id="CompanyName" name="customer[company]" required>
<option value="A" >Your companyA...</option>
<option value="B" >Your companyB...</option>
<option value="other" >other company</option>
</select>
{% render 'icon-caret' %}
</div>
</div>
<div class="field hidden" id="companyOther">
<input
type="text"
name="customer[company_other]"
id="CompanyName-Other"
placeholder="Company name"
>
<label for="CompanyName-Other">
Company name
</label>
</div>
<script>
let CompanyName = document.getElementById("CompanyName")
let companyOther = document.getElementById("companyOther")
CompanyName.onchange=function(){
if (this.value == "other") {
companyOther .className = "field"
}else{
companyOther .className = "field hidden"
}
}
</script>
You can try this.
This is an accepted solution.
<div class="field">
<label for="CompanyName">Company</label>
<div class="select" >
<select id="CompanyName" name="customer[company]" required>
<option value="A" >Your companyA...</option>
<option value="B" >Your companyB...</option>
<option value="other" >other company</option>
</select>
{% render 'icon-caret' %}
</div>
</div>
<div class="field hidden" id="companyOther">
<input
type="text"
name="customer[company_other]"
id="CompanyName-Other"
placeholder="Company name"
>
<label for="CompanyName-Other">
Company name
</label>
</div>
<script>
let CompanyName = document.getElementById("CompanyName")
let companyOther = document.getElementById("companyOther")
CompanyName.onchange=function(){
if (this.value == "other") {
companyOther .className = "field"
}else{
companyOther .className = "field hidden"
}
}
</script>
You can try this.
Thanks, Simonsron,
the "required" location was what I am looking for... Thanks
<select id="CompanyName" name="customer[company]" required>
You are welcome!
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024