Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [AJAX][Java][JavaScript] dynamiczna zmiana buttonu i pola input
shpaque
post
Post #1





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


Pomożecie? (IMG:style_emoticons/default/smile.gif)

o ile button przeskakuje na "Anuluj" - to nie wraca i poza tym nic sie nie dzieje:

  1. <?php
  2. $countCats = count($catalog);
  3.  
  4. if ($countCats < 1)
  5. {
  6. echo "Ten klient nie ma dodanego żadnego katalogu.<br>";
  7. echo "<button class=\"btn btn-md text-center btn-submit\" type=\"submit\" name=\"addcat\"><b>Dodaj katalog</b></button>";
  8. }
  9. else
  10. {
  11. for ($i = 0; $i < $countCats; $i++)
  12. {
  13. $lp = $i+1;
  14.  
  15. echo "
  16. <div class=\"row\">
  17. <div class=\"col-sm-1\">
  18. <div class=\"form-group\">
  19. <label>Lp</label>
  20. <input class=\"form-control text-center\" type=\"text\" name=\"lp\" value=\"".$lp."\" disabled />
  21. </div>
  22. </div>
  23. <div class=\"col-sm-4\">
  24. <div class=\"form-group\">
  25. <label>Tytuł katalogu</label>
  26. <input class=\"form-control text-center\" type=\"text\" name=\"newCatalogTitle".$i."\" value=\"".$catalog[$i] -> title."\" required />
  27. </div>
  28. </div>
  29. <div class=\"col-sm-2\">
  30. <div class=\"form-group\">
  31. <label>Plik katalogu</label>
  32. <input class=\"form-control text-center\" type=\"text\" id=\"newCatalogFile".$i."\" name=\"newCatalogFile".$i."\" value=\"".$catalog[$i] -> file."\" required disabled />
  33. </div>
  34. </div>
  35. <div class=\"col-sm-1\">
  36. <div class=\"form-group\">
  37. <label></label>
  38. <button class=\"btn btn-md text-center btn-back\" type=\"button\" id=\"changeCatFile".$i."\" name=\"changeCatFile".$i."\" onclick=\"changeFile();\">Zmień plik</button>
  39. </div>
  40. </div>
  41. </div>
  42. ";
  43.  
  44. echo "
  45. <script>
  46. function changeFile(){
  47. $(document).ready(function(){
  48. if ($('#newCatalogFile".$i."').prop('type: text')){
  49. $('#changeCatFile".$i."').html('Zmień plik');
  50. $('#newCatalogFile".$i."').prop('type: text', 'disabled: true');
  51. }
  52. else{
  53. $('#changeCatFile".$i."').html('Anuluj');
  54. $('#newCatalogFile".$i."').prop('type: file', 'disabled: false');
  55. }
  56. });
  57. }
  58. </script>
  59. ";
  60. }
  61. }
  62. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
shpaque
post
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


nr katalogu, bo to wszystko jest zapetlone w php

wycinek wyglada tak:

  1. <!-- Katalogi -->
  2. <div class="row">
  3. <div class="col-sm-12 text-center" id="catalogs">
  4. <p style="margin: 10px 0 20px 0;"><b><?php echo $customerName; ?> / Katalogi produktowe</b></p>
  5.  
  6. <?php
  7. $countCats = count($catalog);
  8.  
  9. if ($countCats < 1)
  10. {
  11. echo "Ten klient nie ma dodanego żadnego katalogu.<br>";
  12. echo "<button class=\"btn btn-md text-center btn-submit\" type=\"submit\" name=\"addcat\"><b>Dodaj katalog</b></button>";
  13. }
  14. else
  15. {
  16. for ($i = 0; $i < $countCats; $i++)
  17. {
  18. $lp = $i+1;
  19.  
  20. echo "
  21. <div class=\"row\">
  22. <div class=\"col-sm-1\">
  23. <div class=\"form-group\">
  24. <label>Lp</label>
  25. <input class=\"form-control text-center\" type=\"text\" name=\"lp\" value=\"".$lp."\" disabled />
  26. </div>
  27. </div>
  28. <div class=\"col-sm-4\">
  29. <div class=\"form-group\">
  30. <label>Tytuł katalogu</label>
  31. <input class=\"form-control text-center\" type=\"text\" name=\"newCatalogTitle".$i."\" value=\"".$catalog[$i] -> title."\" required />
  32. </div>
  33. </div>
  34. <div class=\"col-sm-3\">
  35. <div class=\"form-group\">
  36. <label>Plik katalogu</label>
  37. <input class=\"form-control text-center\" type=\"text\" id=\"newCatalogFile".$i."\" name=\"newCatalogFile".$i."\" value=\"".$catalog[$i] -> file."\" required disabled />
  38. </div>
  39. </div>
  40. <div class=\"col-sm-1\">
  41. <div class=\"form-group\">
  42. <label>Zmień plik</label>
  43. <button class=\"btn btn-md text-center btn-back\" type=\"button\" id=\"changeCatFile".$i."\" name=\"changeCatFile".$i."\" style=\"width: 100%;\"><span id=\"icon".$i."\" class=\"fa fa-exchange icon-md\"></span></button>
  44. </div>
  45. </div>
  46. </div>
  47. ";
  48.  
  49. // Przełącznik buttona zmianiającego pole dodawania pliku katalogu
  50. echo "
  51. <script>
  52. var i = 0;
  53. $('#changeCatFile".$i."').click(function() {
  54. if (i == 0) {
  55. document.getElementById('newCatalogFile".$i."').setAttribute('type', 'file');
  56. document.getElementById('newCatalogFile".$i."').disabled = false;
  57. $('#icon".$i."').html('Anuluj');
  58. i = 1;
  59. }
  60. else {
  61. document.getElementById('newCatalogFile".$i."').setAttribute('type', 'text');
  62. document.getElementById('newCatalogFile".$i."').disabled = true;
  63. $('#icon".$i."').html('Zmień plik');
  64. i = 0;
  65. }
  66. });
  67. </script>
  68. ";
  69. }
  70. }
  71. ?>
  72. </div>
  73. </div>
  74. <!-- Koniec katalogów -->





@EDIT


zmienilem wszystko na jquery i znow umarlo no i czego??

  1. var i = 0;
  2. $('#editCat".$i."').click(function() {
  3. if (i == 0) {
  4. $('#newCatalogFile".$i."').attr('type', 'file').attr('disabled', false);
  5. $('#icon".$i."').attr('class', 'fa fa-remove icon-md').attr('title', 'Anuluj zmianę pliku');
  6. $('#label-zmien".$i."').html('Anuluj');
  7. i = 1;
  8. }
  9. else {
  10. $('#newCatalogFile".$i."').attr('type', 'text').attr('disabled', true);
  11. $('#icon".$i."').attr('class', 'fa fa-exchange icon-md').attr('title', 'Kliknij w przycisk aby zmienić plik katalogu');
  12. $('#label-zmien".$i."').html('Zmień plik');
  13. i = 0;
  14. }
  15. });
  16. </script>


no dobra zla zmienna. Temato do zamkniecia dziekuje
Go to the top of the page
+Quote Post

Posty w temacie
- shpaque   [AJAX][Java][JavaScript] dynamiczna zmiana buttonu i pola input   11.06.2018, 14:46:39
- - nospor   wywal to $(document).ready(function(){ i sta...   11.06.2018, 14:50:54
- - shpaque   teraz nawet button sie nie przelacza - w ogole nie...   11.06.2018, 14:54:36
- - nospor   pokaz kod po zmianach bo rozumiem ze oprocz ...   11.06.2018, 14:55:36
- - shpaque   [HTML] pobierz, plaintext <script> ...   11.06.2018, 14:56:59
- - nospor   Jednak nie wywaliles..... tylle czasu z js sie baw...   11.06.2018, 14:58:13
- - trueblue   http://api.jquery.com/prop/   11.06.2018, 14:59:42
- - shpaque   to co tak? tez nie idzie [HTML] pobierz, plaintex...   11.06.2018, 15:04:09
- - nospor   Tak, wlasnie tak. Teraz przejdzmy dalej. Proste de...   11.06.2018, 15:06:24
- - shpaque   ale ja mam w konsoli pusto   11.06.2018, 15:08:34
- - nospor   Niemozliwe. Przy poprzednim kodzie gdzie zostawile...   11.06.2018, 15:09:45
- - shpaque   nie mam alertow za to wyswietla mi tresc pod spode...   11.06.2018, 15:11:36
- - nospor   No ale miales to dac w sekcji SCRIPT   11.06.2018, 15:12:32
- - shpaque   index.php?page=edit&id=227632&c=Brunner:28...   11.06.2018, 15:13:51
- - nospor   Super, jak juz opanowales proste debugowanie to te...   11.06.2018, 15:15:57
- - shpaque   [HTML] pobierz, plaintext <script>$( ...   11.06.2018, 15:20:11
- - Neutral   Czy mógłbyś nakreślić, co dokładnie próbujesz osią...   11.06.2018, 15:41:49
- - shpaque   nie,m to akurat byl przyklad. chce za pomoca czeg...   11.06.2018, 17:37:01
- - Neutral   [HTML] pobierz, plaintext <button id="chan...   11.06.2018, 17:58:18
- - Neutral   Koddocument.getElementById('changeCatFile...   11.06.2018, 18:11:11
- - shpaque   czyli teraz opcja mieszanka: [HTML] pobierz, plai...   11.06.2018, 18:21:39
- - Neutral   Nie jestem jakimś zwolennikiem JQuery, wolałbym ab...   11.06.2018, 18:33:36
- - shpaque   nr katalogu, bo to wszystko jest zapetlone w php ...   11.06.2018, 19:35:12
- - Neutral   Pozmieniaj sobie te apostrofy/cudzysłowy, tam gdzi...   11.06.2018, 19:40:28


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: 14.10.2025 - 14:25