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
 
Start new topic
Odpowiedzi
starach
post
Post #2





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

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


OK. Dzięki.
Mam teraz inny problem.

  1. $("select.tables option").click(
  2. function()
  3. {
  4. var database = $(this).parent().attr("id")
  5. var table = this.text
  6.  
  7. var form = $("form#selected-tables");
  8. var template = $("div#template");
  9.  
  10. var new_input_db = $("input[name='databases\[\]']", template).val(database);
  11. var new_input_table = $("input[name='tables\[\]']", template).val(table);
  12.  
  13. alert(new_input_db.val() + "\n" + new_input_table.val())
  14.  
  15. $("input[name='tables\[\]']", template).replaceWith(new_input_db);
  16. $("input[name='databases\[\]']", template).replaceWith(new_input_db);
  17.  
  18. form.append(template.html())
  19. });

Niestety replaceWith nie działa. Próbowałem już też użyć .html() do new_input_*, ale tak też działać raczej nie będzie bo input nie jest elementem blokowym ee to znaczy nie ma tagu zamykającego. Jak mam teraz przypisać do zmiennej template zmienione znaczniki input?
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: 12.10.2025 - 07:48