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!
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025