Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Łączenie eventów "OnClick", jak można je polaczyc ??
Cog
post 1.06.2009, 22:30:40
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 1.06.2009

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


Witam ,
Jako , ze nie znalazlem takiego tematu na forum pytam w swoim watku.

Przechodzac do sedna :
Robie znajomemu generator , niestety do tego potrzebuje 2 "onClick". Znalazlem 2 skrypty , ktore wykorzystuja 2 rozne , jednak nie wiem jak je polaczyc.


Oto Funkcja:
CODE
<script LANGUAGE="JavaScript">

function countChoices(obj) {
max = 1;

box1 = obj.form.box1.checked;
box2 = obj.form.box2.checked;

count = (box1 ? 1 : 0) + (box2 ? 1 : 0)

if (count > max) {
alert("Oops! You can only choose up to " + max + " choices! \nUncheck an option if you want to pick another.");
obj.checked = false;
}
}
</script>


Tutaj "OnClick" Do niej:
CODE
onClick="countChoices(this)"



A tutaj drugi "onClick":
CODE
<input type="checkbox" name="box1" onClick="document.getElementById('id').style.display = this.checked ? 'block' : 'none'; this.form.elements['nazwa2'].disabled = this.form.elements['nazwa3'].disabled = !this.checked>Sekcja1



Probowalem to zrobic na takiej zasadzie , jednak nie dzialalo :
CODE
<input type="checkbox" name="box2" onClick="document.getElementById('id).style.display = this.checked ? 'block' : 'none'; this.form.elements['nazwa2'].disabled = this.form.elements['nazwa3'].disabled = !this.checked.countChoices(this)">Section 1




Prosilbym o szybka pomoc i z gory dziekuje.
Go to the top of the page
+Quote Post
Crozin
post 1.06.2009, 23:20:00
Post #2





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

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


Najprościej:
  1. <input.... onclick="funkcja1(); funkcja2();">
Poprostu kolejne instrukcje oddzielasz średnikiem o ile go już nie ma.
Go to the top of the page
+Quote Post
Cog
post 1.06.2009, 23:40:05
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 1.06.2009

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


Problem polega na tym , ze to nie sa 2 funkcje. Tylko "countChoices(this)" jest funkcja. Pierwszy czlon nie ma zapisanej nigdzie indziej funkcji.
Go to the top of the page
+Quote Post
melkorm
post 2.06.2009, 00:00:17
Post #4





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


Kod
this.form.elements['nazwa2'].disabled = this.form.elements['nazwa3'].disabled = !this.checked.countChoices(this)


Imo tu masz błąd instrukcje w JS oddzielasz średnikami, nie ważne czy to sa funkcje czy nie. Uzyj fireBug'a do spardzania błędów JS'a w konsoli winksmiley.jpg


--------------------
Go to the top of the page
+Quote Post
Cog
post 2.06.2009, 16:54:56
Post #5





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 1.06.2009

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


Probowalem tak jak napisaliscie , niestety dalej nie chce dzialac.. Firebug - nie umiem tego obsluzyc. Nie ukrywam , ze leze jesli chodzi o JS i PHP , stad tez wlasnie tutaj napisalem problem.

Jesli chodzi o "onClick"i , to sa one z gotowych skryptow - nie pisalem ich sam

Ten post edytował Cog 2.06.2009, 16:55:40
Go to the top of the page
+Quote Post
Crozin
post 2.06.2009, 19:10:54
Post #6





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

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


Pokaż jak próbowałeś.
Go to the top of the page
+Quote Post
Cog
post 2.06.2009, 19:20:51
Post #7





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 1.06.2009

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


CODE

<input type="checkbox" name="box2" onClick="document.getElementById('Rasyproste').style.display = this.checked ? 'block' : 'none'; this.form.elements['nazwa2'].disabled = this.form.elements['nazwa3'].disabled = !this.checked; countChoices(this)">Section 2


Jeszcze tak:
CODE

<input type="checkbox" name="box2" onClick="document.getElementById('Rasyproste').style.display = this.checked ? 'block' : 'none'; this.form.elements['nazwa2'].disabled = this.form.elements['nazwa3'].disabled = !this.checked" onClick="countChoices(this)">Section 2



Edit:
Dzieki wam za pomoc. Juz sobie poradzilem winksmiley.jpg Tak na przyszlosc - dodalem drugiego eventa - "onChange" i zadzialalo

Ten post edytował Cog 2.06.2009, 22:25:33
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 00:48