Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery] Zmiana wartości value pola input
starach
post
Post #1





Grupa: Zarejestrowani
Postów: 999
Pomógł: 30
Dołączył: 14.01.2007
Skąd: wiesz ?

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


alert(cos.val()) Wyświetla "inny tekst" ale druga linijka już nie. To chyba znaczy że on zmienia ten tekst w kopi zmiennej template a nie w tej zmiennej. Oprócz tego dodawany do formularza jest bez problemu.
  1. <script type="text/javascript">
  2. $(document).ready(function()
  3. {
  4. $("select#databases option").click(
  5. function()
  6. {
  7. hideAll();
  8. $("select#" + this.text).css("display", "block")
  9. });
  10. $("select.tables option").click(
  11. function()
  12. {
  13. var database = $(this).parent().attr("id")
  14. var table = this.text
  15.  
  16. var form = $("form#selected-tables");
  17. var template = $("div#template").html();
  18.  
  19. var cos = $("input[name='databases[]']", template).val("inny tekst")
  20. // TUTAJ JEST PROBLEM
  21. alert(cos.val())
  22. alert($("input[name='databases[]']", template).val())
  23.  
  24. form.append(template)
  25. });
  26. });
  27. function hideAll()
  28. {
  29. $("select#databases option").each(function()
  30. {
  31. $("select#" + this.text).css("display", "none")
  32. })
  33. }
  34. <style type="text/css">
  35. select { float:left; width:25%; height:200px; margin:0; border:0; }
  36. select.tables { width:75%; display:none; }
  37. input.add { width:100%; }
  38. div.table { margin:0.5em; }
  39. div#template { display:none; }
  40. <select id="databases" multiple>
  41. {foreach from="collection" item="database"}
  42. <option>{$database->getName()}</option>
  43. {/foreach}
  44.  
  45. {foreach from="collection" item="database"}
  46. <select id="{$database->getName()}" class="tables" multiple{if $database->count() == 0} disabled{/if}>
  47. {foreach from="database" item="table"}
  48. <option>{$table->getName()}</option>
  49. {/foreach}
  50. {if $database->count() == 0}<option>No Tables</option>{/if}
  51. {/foreach}
  52. <form id="selected-tables" action="#" method="POST">
  53. <input class="add" type="submit" value="Reverse">
  54. <div id="template"><div class="table">Database: <input name="databases[]" value="tekst" type="text" disabled> Table: <input name="tables[]" type="text" disabled> <input value="-" type="button"></div></div>
  55. </form>
Niestety skrypt forum usuwa mi tabulacje.

Ten post edytował orglee 11.11.2008, 11:19:00
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 21.08.2025 - 12:04