Click here to Skip to main content
15,443,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I am struggling to make my textbox when leaving to have one label error message, i have done it well on one textbox('email). But trying to apply similar logic to these texbox is bit tricky and need some guidance around my logic below.

What I have tried:

HTML
<pre lang="HTML"><pre>       <div class="row">
                            <label for="Address">Address</label>
                            <div class="col-md-6 ">
                                <div class="input-group pull-right">
                                                 
                                    @Html.TextBoxFor(m => m.HomeMainModel.Address, new { @class = "form-control", type = "text", id = " street address", autofocus = "autofocus", placeholder = "Street Address", required = "required" })
                                    <div class="input-group-append">
                                        <div class="input-group-text">

                                        </div>
                                    </div>

                                </div>

                            </div>
                        </div>
                        <div class="col-md-6 col-sm-10 col-xs-10">
                            <label id="labelMessaget" class="text-danger" style="display:none"></label>
                        </div>

<div class="row">
                            <div class="col-md-6 ">
                                <div class="input-group pull-right">
                                                                   
                                    @Html.TextBoxFor(m => m.HomeMainModel.Address, new { @class = "form-control", type = "text", id = "address", autofocus = "autofocus", placeholder = "Street Address Line 2", required = "required" })
                                    <div class="input-group-append">
                                        <div class="input-group-text">
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="col-md-6 col-sm-10 col-xs-10">
                            <label id="labelMessaget" class="text-danger" style="display:none"></label>
                        </div>


<div class="form-group">
                           <div class="input-group mb-2">
                               <div class="input-group-prepend">

                               </div>

                               <div class="input-group col-md-7 col-md-offset-7 col-sm-7 col-xs-7">
                                   <div class="input-group pull-right">
                                                                    
                                       @Html.TextBoxFor(m => m.HomeMainModel.City, new { @class = "form-control", type = "text", id = "city", autofocus = "autofocus", placeholder = "City", required = "required" })             

                                       @Html.TextBoxFor(m => m.HomeMainModel.State, new { @class = "form-control", type = "text", id = "state", autofocus = "autofocus", placeholder = "State/ Province", required = "required" })

                                       <div class="input-group-append">
                                           <div class="input-group-text">
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </div>
                           <div class="col-md-6 col-sm-10 col-xs-10">
                               <label id="labelMessaget" class="text-danger" style="display:none"></label>
                           </div>
                           <hr />
                           <!--Zip code for postal code-->
                           <div class="input-group mb-2">
                               <div class="input-group-append">

                               </div>
                               <div class="input-group col-md-7 col-md-offset-3 col-sm-2 col-xs-2">
                                   <div class="input-group pull-right">
                                                        
                                                  
                                       @Html.TextBoxFor(m => m.HomeMainModel.Code, new
                                  {
                                      @class = "form-control",
                                      type = "text",
                                      id = "postal code",
                                      autofocus = "autofocus",
                                      placeholder = "Postal/Zip Code"

                                       })
                                                         
                                       @Html.DropDownListFor(m => m.HomeMainModel.SelectedCountryId, this.ViewBag.CountryList as SelectList, new { @class = "form-control" })
                                       <div class="input-group-append">
                                           <div class="input-group-text">

                                           </div>
                                       </div>

                                   </div>
                               </div>
                           </div>
                       </div>
                       <div class="col-md-6 col-sm-10 col-xs-10">
                           <label id="labelMessaget" class="text-danger" style="display:none"></label>
                       </div>
Posted
Updated 25-Mar-20 6:26am

1 solution

An ID in an HTML document has to be unique. You have given all of your labels the same ID (labelMessaget), which won't work.

Give each of your labels a different ID.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900