Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Przypisywanie "ukrytej" wartości do 'radio'
Dax13
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 20.06.2009

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


Witam, jestem początkującym programerem (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Przy tworzeniu skryptu do wykonywania opisów do filmów na fora napotkałem problem.
Chcę aby mój skrypt był uniwersalny, aby można było tworzyć opisy do filmów, gier i muzyki.
Oto fragment kodu który jest odpowiedzialny za wyświetlanie odpowiednich pól do podawania danych. Dane te różnią się kategorią np. Film: produkcja, reżyseria itp, natomiast gra: wymagania, dystrybucja itd.
  1. <?php
  2. <input type=radio name=grafika value=film1 checked=checked></span><label for="pole1"><a href = "#" onmouseout = "doButtons('img/wybierzgrafike.png')" onclick="document.getElementById('film1').style.display = this.checked ? 'block' : 'none'; this.form.elements['produkcja'].disabled = this.form.elements['gatunek'].disabled = this.form.elements['premiera'].disabled = this.form.elements['rezyseria'].disabled = this.form.elements['scenariusz'].disabled = this.form.elements['muzyka'].disabled = this.form.elements['lat'].disabled = this.form.elements['czas'].disabled = !this.checked; document.getElementById('film2').style.display = this.checked ? 'block' : 'none'; this.form.elements['avicodec'].disabled = !this.checked; document.getElementById('film3').style.display = this.checked ? 'block' : 'none'; this.form.elements['obsada1'].disabled = !this.checked"></span></a></label><strong>Film1</strong>
  3. ?>
(kod użyczył mi kolega na uczenie się programowania)
Chcę aby przy zaznaczeniu opcji 'Film' wyświetlały się pola odpowiedzialne za opis do filmu, a do gier pola odpowiedzialne za gry.
kod powyżej odnosi się narazie tylko do filmów, niestety skrypt nie działa tak jak bym chciał, po wybraniu opcji 'Film' nie pokazują się żadne nowe pola do wypełnienia (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Oto dalsza część kodu:

  1. <?php
  2. <div id="film1" style="display: none">
  3. <strong>Produkcja: </strong> <input type=text name=produkcja style="width: 50%"><br>
  4. Gatunek: <input type=text name=gatunek style="width: 50%"><br>
  5. Data premiery: <input type=text name=premiera style="width: 50%"><br>
  6. Reżyseria: <input type=text name=rezyseria style="width: 50%"><br>
  7. Scenariusz: <input type=text name=scenariusz style="width: 50%"><br>
  8. Muzyka: <input type=text name=muzyka style="width: 50%"><br>
  9. Od lat: <input type=text name=lat style="width: 50%"><br>
  10. Czas trwania (min): <input type=text name=czas style="width: 50%"></span>
  11. </div>
  12. ?>


Z góry dziękuję za pomoc
Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
cyklotrial
post
Post #2





Grupa: Zarejestrowani
Postów: 11
Pomógł: 1
Dołączył: 5.06.2009

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


Ja użyłbym tutaj jQuery

  1. <script language="javascript">
  2. function showHide(obj)
  3. {
  4. var showDiv = "#"+obj;
  5. $("div").slideUp("slow");
  6. $(showDiv).slideDown("slow");
  7. }

  1. <input type="radio" name="film" onChange="showHide(this.value)" value="film" id="input_radio_film"> <label for="input_radio_film">FILM</label><br>
  2. <div id= "film" style="display:none">
  3. a: <input type="text" size="30" maxlength="36" name="" value=""><br>
  4. b: <input type="text" size="30" maxlength="36" name="" value=""><br>
  5. c: <input type="text" size="30" maxlength="36" name="" value="">
  6. </div>
  7. <input type="radio" name="gry" onChange="showHide(this.value)" value="gry" id="input_radio_gry"><label for="input_radio_gry">Gry</label>
  8.  
  9. <div id= "gry" style="display:none">
  10. a: <input type="text" size="30" maxlength="36" name="" value=""><br>
  11. b: <input type="text" size="30" maxlength="36" name="" value=""><br>
  12. c: <input type="text" size="30" maxlength="36" name="" value="">
  13. </div>


aby dodać kolejne kategorie podam mały wzór:
  1. <input type="radio" name="nowa_kat" onChange="showHide(this.value)" value="nowa_kat" id="input_radio_nowa_kat"> <label for="input_radio_nowa_kat">FILM</label><br>
  2. <div id= "nowa_kat" style="display:none">
  3. a: <input type="text" size="30" maxlength="36" name="" value=""><br>
  4. </div>

Przy czym należy pamiętać o tym żeby value inputa było takie samo jak id ukrytego diva

Pozdrawiam
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 - 15:07