Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
¿Cómo tener un máximo para un elemento de solo lectura?

Así que digamos que tengo un código que se ve así y quiero que el formulario solo se envíe si la suma de xey es 10 o menos. Ahora, cuando ejecuto este código, ignora por completo el "máximo" y simplemente envía el formulario. Tan pronto como elimino el "solo lectura", se ve el "máximo". ¿Hay alguna forma de tener un máximo para un elemento de solo lectura? Y si es así, ¿cómo?

 <!DOCTYPE html> <html> <head> <title>Max for readonly</title> </head> <body> <script> var x = 5; var y = 7; var sum = x + y; document.getElementById('demo').value = sum; </script> <form> <input id="demo" type="number" max="10" readonly> <input type="submit"> </form> </body> </html>

Gracias por adelantado

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puede hacer esto: document.getElementById('demo').value = sum; si en el momento actual la entrada con id = 'demo' es de solo lectura. En su caso, no está realizando una asignación, porque el elemento es de solo lectura. Es por eso que el control máximo no funciona para usted. Ya que no hay valor allí. Puede hacer una suma y solo luego establecer su entrada readonly = true;

 <!DOCTYPE html> <html> <head> <title>Max for readonly</title> </head> <body> <script> var x = 5; var y = 7; var sum = x + y; document.getElementById('demo').value = sum; document.getElementById('demo').readOnly = true; </script> <form> <input id="demo" type="number" max="10"> <input type="submit"> </form> </body> </html> 

 <!DOCTYPE html> <html> <head> <title>Max for readonly</title> </head> <body> <form> <input id="demo" type="number" max="10"> <input type="submit"> </form> <script> var x = 5; var y = 7; var sum = x + y; document.getElementById('demo').value = sum; document.getElementById('demo').readOnly = true; </script> </body> </html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!