Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobranie najwięszego ID z form
tmk
post
Post #1





Grupa: Zarejestrowani
Postów: 135
Pomógł: 0
Dołączył: 15.04.2004
Skąd: w-wa

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


Witam, mam formularz, w którym są inputy. Każdy z nich ma id, pokolei id=1, id=2 itd...

Potrzebuję funkcję, która mi poda największe id występujące w inputach.
Macie jakiś pomysł jak możnaby to rozwiązać?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




  1. <input type="text" id="1" />
  2. <input type="text" id="2" />
  3. <input type="text" id="3" />
  4. <input type="text" id="4" />
  5.  
  6. <button onclick="getMaxValue();">licz</button>
  7. <script language="javascript">
  8. function getMaxValue()
  9. {
  10. i = 1;
  11. maxI = null; maxValue=null;
  12. while (true){
  13. obj = document.getElementById(i);
  14. if (!obj) break;
  15. if (maxValue == null || obj.value > maxValue)
  16. {
  17. maxValue = obj.value;
  18. maxI = i;
  19. }
  20. i++;
  21. }
  22.  
  23. alert('MaxValue: '+maxValue+' dla id='+maxI);
  24. }
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: 13.10.2025 - 20:57