Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]sprawdzenie czy input to liczba
sadistic_son
post
Post #1





Grupa: Zarejestrowani
Postów: 1 495
Pomógł: 245
Dołączył: 1.07.2009
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Cześć,
Prosty skrypcik sprawdzający czy w input type="number" wpisano liczbę. Dlaczego za żadne skarby nie chce wykonać się warunek i ciągle pokazuje drugi komunikat? Konsola nic nie zwraca - czysto.
[JAVASCRIPT] pobierz, plaintext
  1. function checkNumber() {
  2. var price = document.forms["product_form"]["price"].value;
  3. let ele = document.getElementById('alertMessage');
  4. if (typeof price == 'number') {
  5. // if (typeof price == 'number' && !isNaN(price)) { tak też próbowałem
  6. ele.innerHTML = 'Powinno przejść';
  7. return true;
  8. } else {
  9. ele.innerHTML = 'Please, provide the data of indicated type';
  10. return false;
  11. }
  12. }
[JAVASCRIPT] pobierz, plaintext

  1. <form method="POST" id="product_form" name="product_form" onsubmit="return checkNumber()" action="http://xxx.pl">
  2. <button type="submit" name="save">Save</button>
  3. <input type="number" id="price" name="price" />
  4. </form>
  5. <div id="alertMessage"></div>


Ten post edytował sadistic_son 11.01.2023, 12:36:36
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 23:16