Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

431
Vistas
Multiple Checkbox - Change Message "Please check this box if you want to proceed"

I have a multiselect checkbox form to which I add a JS to make sure the visitor selects at least one option

<div class="form-group options">
<label class="control-label col-md-4" for="optiontext">Specify an option</label>
<div class="col-md-6">
    <input type="checkbox" name="option[]" value="option1" required/> Option 1<br>
    <input type="checkbox" name="option[]" value="option2" required/> Option 2<br>
    <input type="checkbox" name="option[]" value="option3" required/> Option 3<br>
    <input type="checkbox" name="option[]" value="option4" required/> Option 4<br>
    <input type="checkbox" name="option[]" value="option5" required/> Option 5<br>
    <input type="checkbox" name="option[]" value="option6" required/> Option 6<br>
    <input type="checkbox" name="option[]" value="option7" required/>  Option 7
</div>

That's the JS

$(function(){
var requiredCheckboxes = $('.options :checkbox[required]');
requiredCheckboxes.change(function(){
    if(requiredCheckboxes.is(':checked')) {
        requiredCheckboxes.removeAttr('required');
    } else {
        requiredCheckboxes.attr('required', 'required');
    }
});

Now ALL IS WORKING fine, the only thing is that the error message that comes up is Please check this box if you want to proceed but I would like the message to be Please select at least one option to proceed like illustrated on the picture here.

enter image description here

How do I go about it?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

It's very simple to control custom messages with the help of HTML5 event oninvalid

Code:

<input type="checkbox" value="option1"
   oninvalid="this.setCustomValidity('Please select at least one option to proceed')">
about 4 years ago · Santiago Trujillo Denunciar

0

I implemented this as follows:

    <html>
    <head>
        <title>test</title>
    </head>
    <body>
        <form>
            <input type="checkbox" id="sterms" value="Agreed-to-Terms" onclick ="if (!this.checked) {this.setCustomValidity('برای ادامه لطفا این گزینه را تیک بزنید.');} else {this.setCustomValidity('');}" required>
                                <a href="privacy-policy.html">قوانین و شرایط استفاده را می پذیرم.</a>
            <button type="submit" class="form-control-submit-button">انجام آزمایش</button>
        </form>
        <script type="text/javascript">
            document.getElementById("sterms").setCustomValidity('برای ادامه لطفا این گزینه را تیک بزنید.');
        </script>
    </body>
</html>
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda