Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][JavaScript] Długość tablicy/stringa
Forum PHP.pl > Forum > Przedszkole
Fifi209
Mam taki problem, postanowiłem podszkolić się w JavaScript i chciałem do swojej strony zrobić taką "klawiaturę"

Tutaj kod całej strony + html
CODE

<html>
<head>
<title>Testy</title>
<script type="text/javascript">
function dodaj(co) {
if (co) {
document.getElementById('pole').value += co;
}else{
alert('Co mam dodać?!');
}
}

function usun(co) {
var dane = document.getElementById('pole').value;
if (dane) {
if (co) {
dane = substr(0, dane.lenght-co);
// Żadnen w komentarzu nie działa
// dane = substr(0, dane.lenght-1);
// dane = substring(0, dane.lenght-co);
// dane = substring(0, dane.lenght-1);

document.getElementById('pole').value = dane;
}else{
document.getElementById('pole').value = '';
}
}else{
alert('Co mam usunąć!?');
}
}
</script>
</head>
<body>
<center>
<table>
<tr>
<td><input type="submit" value="1" onclick="dodaj(1)"></td><td><input type="submit" value="2" onclick="dodaj(2)"></td>
<td><input type="submit" value="<-" onclick="usun(1)"></td>
</tr>
<tr>
<td><input type="submit" value="3" onclick="dodaj(3)"></td><td><input type="submit" value="4" onclick="dodaj(4)"></td>
<td><input type="submit" value="Reset" onclick="usun()"></td>
</tr>
</table>
<input type="text" id="pole" disabled="disabled">
</center>
</body>
</html>




Funkcja resetowania działa, ale jak chcę usunąć jeden znak to nic się nie dzieje...
Oczywiście dodawanie znaków działa bezproblemowo...
wookieb
https://developer.mozilla.org/pl/Dokumentac...y/String/substr
Uzyles "funkcje" na niczym
Fifi209
Po zmianie z:
Kod
dane = substr(0, dane.lenght-1);


na:
Kod
dane = dane.substr(0, dane.lenght-1);


Usuwa mi cały ciąg, zamiast ostatniego znaku.

W dodatku:

Kod
alert(dane.lenght);


Wyświetla:
Cytat
undefined
wookieb
Kod
dane.length
Fifi209
Cytat(wookieb @ 22.03.2009, 12:15:53 ) *
Kod
dane.length


Dzięki bardzo ("pomógł" 2x), jestem jednak debil. ;d
ctr+c ctr+v jak widać nie dobra metoda. Bo raz strzeliłem literówkę i tak zostało. ;d
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.