Pomożecie?
o ile button przeskakuje na "Anuluj" - to nie wraca i poza tym nic sie nie dzieje:
<?php $countCats = http://www.php.net/count($catalog); if ($countCats < 1) { http://www.php.net/echo "Ten klient nie ma dodanego żadnego katalogu.<br>"; http://www.php.net/echo "<button class=\"btn btn-md text-center btn-submit\" type=\"submit\" name=\"addcat\"><b>Dodaj katalog</b></button>"; } else { for ($i = 0; $i < $countCats; $i++) { $lp = $i+1; http://www.php.net/echo " <div class=\"row\"> <div class=\"col-sm-1\"> <div class=\"form-group\"> <label>Lp</label> <input class=\"form-control text-center\" type=\"text\" name=\"lp\" value=\"".$lp."\" disabled /> </div> </div> <div class=\"col-sm-4\"> <div class=\"form-group\"> <label>Tytuł katalogu</label> <input class=\"form-control text-center\" type=\"text\" name=\"newCatalogTitle".$i."\" value=\"".$catalog[$i] -> title."\" required /> </div> </div> <div class=\"col-sm-2\"> <div class=\"form-group\"> <label>Plik katalogu</label> <input class=\"form-control text-center\" type=\"text\" id=\"newCatalogFile".$i."\" name=\"newCatalogFile".$i."\" value=\"".$catalog[$i] -> http://www.php.net/file."\" required disabled /> </div> </div> <div class=\"col-sm-1\"> <div class=\"form-group\"> <label></label> <button class=\"btn btn-md text-center btn-back\" type=\"button\" id=\"changeCatFile".$i."\" name=\"changeCatFile".$i."\" onclick=\"changeFile();\">Zmień plik</button> </div> </div> </div> "; http://www.php.net/echo " <script> function changeFile(){ $(document).ready(function(){ if ($('#newCatalogFile".$i."').prop('type: text')){ $('#changeCatFile".$i."').html('Zmień plik'); $('#newCatalogFile".$i."').prop('type: text', 'disabled: true'); } else{ $('#changeCatFile".$i."').html('Anuluj'); $('#newCatalogFile".$i."').prop('type: file', 'disabled: false'); } }); } </script> "; } } ?>
wywal to
$(document).ready(function(){
i staraj sie na przyszlosc doczytac co robia rzeczy ktorych uzywasz bo potem takie kwiatki
teraz nawet button sie nie przelacza - w ogole nieaktywny
pokaz kod po zmianach
bo rozumiem ze oprocz
$(document).ready(function(){
wywaliles tez koncowke tej funkcji czyli jeden } oraz jeden ) ?
<http://december.com/html/4/element/script.html> function changeFile(){ if ($('#newCatalogFile".$i."').prop('type: text')){ $('#newCatalogFile".$i."').prop('type: text', 'disabled: true'); $('#changeCatFile".$i."').html('Zmień plik'); } else{ $('#newCatalogFile".$i."').prop('type: file', 'disabled: false'); $('#changeCatFile".$i."').html('Anuluj'); } }); </http://december.com/html/4/element/script.html>
Jednak nie wywaliles..... tylle czasu z js sie bawisz i nawet do konsoli bledow nie zagladasz jeszcze?
http://api.jquery.com/prop/
to co tak? tez nie idzie
<http://december.com/html/4/element/script.html> function changeFile(){ if ($('#newCatalogFile".$i."').prop('type: text')){ $('#newCatalogFile".$i."').prop('type: text'); $('#newCatalogFile".$i."').attr('disabled: true'); $('#changeCatFile".$i."').html('Zmień plik'); } else{ $('#newCatalogFile".$i."').prop('type: file'); $('#newCatalogFile".$i."').attr('disabled: false'); $('#changeCatFile".$i."').html('Anuluj'); } } </http://december.com/html/4/element/script.html>
Tak, wlasnie tak. Teraz przejdzmy dalej. Proste debugowanie:
ale ja mam w konsoli pusto
Niemozliwe. Przy poprzednim kodzie gdzie zostawiles }) powinienies miec bledy w konsoli. Moze patrzysz nie na te konsole co trzeba... Ja mowie o konsoli przegladarki.
Niewazne, odpal debug co ci podalem
nie mam alertow za to wyswietla mi tresc pod spodem:
function changeFile(){ if ($('#newCatalogFile0').prop('type: text')){ alert("Widzisz 1?"); $('#newCatalogFile0').prop('type: text'); $('#newCatalogFile0').attr('disabled: true'); $('#changeCatFile0').html('Zmień plik'); } else{ alert("A moze widzisz 2?"); $('#newCatalogFile0').prop('type: file'); $('#newCatalogFile0').attr('disabled: false'); $('#changeCatFile0').html('Anuluj'); } }
No ale miales to dac w sekcji SCRIPT
index.php?page=edit&id=227632&c=Brunner:287 Uncaught ReferenceError: changeFile is not defined
at HTMLButtonElement.onclick (index.php?page=edit&id=227632&c=Brunner:287)
oj kurde wkleilem calosc i wywalilo scripty
wywala od razu 2
Super, jak juz opanowales proste debugowanie to teraz sie wkoncu skup i zajrzyj do linka co podal trueblue bo zle uzywasz prop().
To po pierwsze
A po drugie masz totalnie zla logike:
jesli TYPE jest text to ustaw TYPE na text.
No przeciez to nie ma zadnego sensu.
Zebys lepiej zrozumial:
Jesli x to 3 to ustaw x na 3
w przeciwnym wypadku ustaw x na "nie3"
<http://december.com/html/4/element/script.html> $( "input" ).change(function() { var $input = $( this ); $( "p" ).html( ".attr( \"checked\" ): <http://december.com/html/4/element/b.html>" + $input.attr( "checked" ) + "</http://december.com/html/4/element/b.html><http://december.com/html/4/element/br.html>" + ".prop( \"checked\" ): <http://december.com/html/4/element/b.html>" + $input.prop( "checked" ) + "</http://december.com/html/4/element/b.html><http://december.com/html/4/element/br.html>" + ".is( \":checked\" ): <http://december.com/html/4/element/b.html>" + $input.is( ":checked" ) + "</http://december.com/html/4/element/b.html>" ); }).change(); </http://december.com/html/4/element/script.html>
Czy mógłbyś nakreślić, co dokładnie próbujesz osiągnąć?
Czy chodzi Ci o wzięcie wartości z input type checkbox?
nie,m to akurat byl przyklad.
chce za pomoca czegos takiego:
<http://december.com/html/4/element/script.html> function changeFile(){ if ($('#newCatalogFile".$i."').attr('type: text')){ $('#newCatalogFile".$i."').prop('disabled'); $('#changeCatFile".$i."').html('Zmień plik'); } else{ $('#newCatalogFile".$i."').attr('type: file'); $('#newCatalogFile".$i."').prop('disabled'); $('#changeCatFile".$i."').html('Anuluj'); } } </http://december.com/html/4/element/script.html>
<http://december.com/html/4/element/button.html id="changeCatFile">changeCatFile</http://december.com/html/4/element/button.html> <http://december.com/html/4/element/input.html type="text" id="newCatalogFile" disabled="disabled"/>
czyli teraz opcja mieszanka:
<http://december.com/html/4/element/script.html> var i = 0; document.getElementById('changeCatFile".$i."').addEventListener('click',function() { if (i == 0) { document.getElementById('newCatalogFile".$i."').setAttribute('type', 'file'); document.getElementById('newCatalogFile".$i."').disabled = false; $('#changeCatFile".$i."').html('Anuluj'); i = 1; } else { document.getElementById('newCatalogFile".$i."').setAttribute('type', 'text'); document.getElementById('newCatalogFile".$i."').disabled = true; $('#changeCatFile".$i."').html('Zmień plik'); i = 0; } }, false); </http://december.com/html/4/element/script.html>
Nie jestem jakimś zwolennikiem JQuery, wolałbym abyś pisał to w PURE JS, ale jeśli się tak uparłeś, to masz:
nr katalogu, bo to wszystko jest zapetlone w php
wycinek wyglada tak:
<!-- Katalogi --> <div class="row"> <div class="col-sm-12 text-center" id="catalogs"> <p style="margin: 10px 0 20px 0;"><b><?php http://www.php.net/echo $customerName; ?> / Katalogi produktowe</b></p> <?php $countCats = http://www.php.net/count($catalog); if ($countCats < 1) { http://www.php.net/echo "Ten klient nie ma dodanego żadnego katalogu.<br>"; http://www.php.net/echo "<button class=\"btn btn-md text-center btn-submit\" type=\"submit\" name=\"addcat\"><b>Dodaj katalog</b></button>"; } else { for ($i = 0; $i < $countCats; $i++) { $lp = $i+1; http://www.php.net/echo " <div class=\"row\"> <div class=\"col-sm-1\"> <div class=\"form-group\"> <label>Lp</label> <input class=\"form-control text-center\" type=\"text\" name=\"lp\" value=\"".$lp."\" disabled /> </div> </div> <div class=\"col-sm-4\"> <div class=\"form-group\"> <label>Tytuł katalogu</label> <input class=\"form-control text-center\" type=\"text\" name=\"newCatalogTitle".$i."\" value=\"".$catalog[$i] -> title."\" required /> </div> </div> <div class=\"col-sm-3\"> <div class=\"form-group\"> <label>Plik katalogu</label> <input class=\"form-control text-center\" type=\"text\" id=\"newCatalogFile".$i."\" name=\"newCatalogFile".$i."\" value=\"".$catalog[$i] -> http://www.php.net/file."\" required disabled /> </div> </div> <div class=\"col-sm-1\"> <div class=\"form-group\"> <label>Zmień plik</label> <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> </div> </div> </div> "; // Przełącznik buttona zmianiającego pole dodawania pliku katalogu http://www.php.net/echo " <script> var i = 0; $('#changeCatFile".$i."').click(function() { if (i == 0) { document.getElementById('newCatalogFile".$i."').setAttribute('type', 'file'); document.getElementById('newCatalogFile".$i."').disabled = false; $('#icon".$i."').html('Anuluj'); i = 1; } else { document.getElementById('newCatalogFile".$i."').setAttribute('type', 'text'); document.getElementById('newCatalogFile".$i."').disabled = true; $('#icon".$i."').html('Zmień plik'); i = 0; } }); </script> "; } } ?> </div> </div> <!-- Koniec katalogów -->
<http://december.com/html/4/element/script.html> var i = 0; $('#editCat".$i."').click(function() { if (i == 0) { $('#newCatalogFile".$i."').attr('type', 'file').attr('disabled', false); $('#icon".$i."').attr('class', 'fa fa-remove icon-md').attr('title', 'Anuluj zmianę pliku'); $('#label-zmien".$i."').html('Anuluj'); i = 1; } else { $('#newCatalogFile".$i."').attr('type', 'text').attr('disabled', true); $('#icon".$i."').attr('class', 'fa fa-exchange icon-md').attr('title', 'Kliknij w przycisk aby zmienić plik katalogu'); $('#label-zmien".$i."').html('Zmień plik'); i = 0; } }); </http://december.com/html/4/element/script.html>
Pozmieniaj sobie te apostrofy/cudzysłowy, tam gdzie masz zmienne, na to:
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)