Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Wypełnianie input z zapytania ajax
niebieszki
post 15.02.2011, 10:20:27
Post #1





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 30.09.2010

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


Witam

Mój problem jest nastepujacy: Stworzyłem formularz z polem input z dynamiczną wyszukiwarką (.ajaxComplete()) Chciałbym aby wyniki mojego wyszukiwania były umieszczanie w kilku polach input bez przeładowywania strony czyli:
wpisuje np. Wr (miasto do pola input) wybieram z listy interesujące miasto [do tego mometu mam]
i po wybraniu kolejne inputy zostają załadowane wartościami z bazy danych (np. pole wojewodztwo, czy kod pocztowy do odpowiednich inputów).

Jak sie za to zabrać? Co powinienem poczytać od czego zacząć aby ugryźć to?
Go to the top of the page
+Quote Post
nospor
post 15.02.2011, 10:22:04
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Korzystam z tego pluginu do jquery:
http://bassistance.de/jquery-plugins/jquer...n-autocomplete/
realizuje dokładnie to czego chcesz - możesz do podpowiadania dodawać dodatkowe dane i robić z nimi co chcesz


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
niebieszki
post 15.02.2011, 10:45:10
Post #3





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 30.09.2010

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


hej dzieki za szybko odpwiedź właśnie chciałem edytowac swojego posta że kozystam z tego pluginu. I znalazlem na stronie w przykładach http://jquery.bassistance.de/autocomplete/demo/ że można p wyszukaniu wstawić pola do inputów... nie mogę tylko znaleźć tej opcji... (zabieram sie za studiowanie dokumentacji)

Ten post edytował niebieszki 15.02.2011, 10:47:12
Go to the top of the page
+Quote Post
nospor
post 15.02.2011, 10:52:26
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Chodzi o funkcję result()

Ze strony co sam podales masz przyklady:
Kod
$("#singleBirdRemote").result(function(event, data, formatted) {
        if (data)
            $(this).parent().next().find("input").val(data[1]);
    });
    $("#suggest4").result(function(event, data, formatted) {
        var hidden = $(this).parent().next().find(">:input");
        hidden.val( (hidden.val() ? hidden.val() + ";" : hidden.val()) + data[1]);
    });

Result jest odpalane po wybraniu podpowiedzi a data zawiera dane, ktore szly jak podpowiedź

Jesli przekazywales dane tak
1
2
3
...
To dodatkowe dane przekazujesz poprzez dodanie |
1|cosinnego|cosinnego2
2|cosinnego|cosinnego2
.......
i data[1], data[2] zawiera dodatkowe dane


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
niebieszki
post 15.02.2011, 11:12:58
Post #5





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 30.09.2010

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


Dziękuję bardzo za pomoc.

Patrzyłem na źródło strony na ten fragment co podałeś ale za szybko myślałem że funkcja się kończy - moje nie dopatrzenie. Dzieki jeszcze raz za wyjaśnienia.
_______________________________________________________
_______________________________________________________

php.gif Mam jednak kolejny problem z tym pluginem.

Przerabiam te przykłady co sa na stronie i tak mnie zastanawia skad sie bierze zmeinna 'q'? Z tablicy superglobalnej Get ale jak tam trafia?

w przykładzie Kod:
  1. $q = strtolower($_GET["q"]);
  2. if (!$q) return;
  3. $items = array(
  4. "Great <em>Bittern</em>"=>"Botaurus stellaris",
  5. "Little <em>Grebe</em>"=>"Tachybaptus ruficollis",
  6. "Black-necked Grebe"=>"Podiceps nigricollis",
  7. "Little Bittern"=>"Ixobrychus minutus",
  8. "Black-crowned Night Heron"=>"Nycticorax nycticorax",
  9. "Purple Heron"=>"Ardea purpurea",
  10. "White Stork"=>"Ciconia ciconia",
  11. "Spoonbill"=>"Platalea leucorodia",
  12. "Red-crested Pochard"=>"Netta rufina",
  13. .
  14. .
  15. .
  16. "Solitary Sandpiper"=>"Tringa solitaria",
  17. "Heuglin's Gull"=>"Larus heuglini"
  18. );
  19.  
  20. foreach ($items as $key=>$value) {
  21. if (strpos(strtolower($key), $q) !== false) {
  22. echo "$key|$value\n";
  23. }
  24. }

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2.  
  3. <title>jQuery Autocomplete Plugin</title>
  4. <script type="text/javascript" src="../lib/jquery.js"></script>
  5. <script type='text/javascript' src='../lib/jquery.bgiframe.min.js'></script>
  6. <script type='text/javascript' src='../lib/jquery.ajaxQueue.js'></script>
  7. <script type='text/javascript' src='../lib/thickbox-compressed.js'></script>
  8. <script type='text/javascript' src='../jquery.autocomplete.js'></script>
  9. <script type='text/javascript' src='localdata.js'></script>
  10. <link rel="stylesheet" type="text/css" href="main.css" />
  11. <link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />
  12. <link rel="stylesheet" type="text/css" href="../lib/thickbox.css" />
  13.  
  14. <script type="text/javascript">
  15. $().ready(function() {
  16.  
  17. function log(event, data, formatted) {
  18. $("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
  19. }
  20.  
  21. function formatItem(row) {
  22. return row[0] + " (<strong>id: " + row[1] + "</strong>)";
  23. }
  24. function formatResult(row) {
  25. return row[0].replace(/(<.+?>)/gi, '');
  26. }
  27.  
  28. $("#suggest1").focus().autocomplete(cities);
  29. $("#month").autocomplete(months, {
  30. minChars: 0,
  31. max: 12,
  32. autoFill: true,
  33. mustMatch: true,
  34. matchContains: false,
  35. scrollHeight: 220,
  36. formatItem: function(data, i, total) {
  37. // don't show the current month in the list of values (for whatever reason)
  38. if ( data[0] == months[new Date().getMonth()] )
  39. return false;
  40. return data[0];
  41. }
  42. });
  43. $("#suggest13").autocomplete(emails, {
  44. minChars: 0,
  45. width: 310,
  46. matchContains: "word",
  47. autoFill: false,
  48. formatItem: function(row, i, max) {
  49. return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
  50. },
  51. formatMatch: function(row, i, max) {
  52. return row.name + " " + row.to;
  53. },
  54. formatResult: function(row) {
  55. return row.to;
  56. }
  57. });
  58. $("#singleBirdRemote").autocomplete("search.php", {
  59. width: 260,
  60. selectFirst: false
  61. });
  62. $("#suggest14").autocomplete(cities, {
  63. matchContains: true,
  64. minChars: 0
  65. });
  66. $("#suggest3").autocomplete(cities, {
  67. multiple: true,
  68. mustMatch: true,
  69. autoFill: true
  70. });
  71. $("#suggest4").autocomplete('search.php', {
  72. width: 300,
  73. multiple: true,
  74. matchContains: true,
  75. formatItem: formatItem,
  76. formatResult: formatResult
  77. });
  78. $("#imageSearch").autocomplete("images.php", {
  79. width: 320,
  80. max: 4,
  81. highlight: false,
  82. scroll: true,
  83. scrollHeight: 300,
  84. formatItem: function(data, i, n, value) {
  85. return "<img src='images/" + value + "'/> " + value.split(".")[0];
  86. },
  87. formatResult: function(data, value) {
  88. return value.split(".")[0];
  89. }
  90. });
  91. $("#tags").autocomplete(["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "pearl"], {
  92. width: 320,
  93. max: 4,
  94. highlight: false,
  95. multiple: true,
  96. multipleSeparator: " ",
  97. scroll: true,
  98. scrollHeight: 300
  99. });
  100.  
  101.  
  102. $(":text, textarea").result(log).next().click(function() {
  103. $(this).prev().search();
  104. });
  105. $("#singleBirdRemote").result(function(event, data, formatted) {
  106. if (data)
  107. $(this).parent().next().find("input").val(data[1]);
  108. });
  109. $("#suggest4").result(function(event, data, formatted) {
  110. var hidden = $(this).parent().next().find(">:input");
  111. hidden.val( (hidden.val() ? hidden.val() + ";" : hidden.val()) + data[1]);
  112. });
  113. $("#suggest15").autocomplete(cities, { scroll: true } );
  114. $("#scrollChange").click(changeScrollHeight);
  115.  
  116. $("#thickboxEmail").autocomplete(emails, {
  117. minChars: 0,
  118. width: 310,
  119. matchContains: true,
  120. highlightItem: false,
  121. formatItem: function(row, i, max, term) {
  122. return row.name.replace(new RegExp("(" + term + ")", "gi"), "<strong>$1</strong>") + "<br><span style='font-size: 80%;'>Email: &lt;" + row.to + "&gt;</span>";
  123. },
  124. formatResult: function(row) {
  125. return row.to;
  126. }
  127. });
  128.  
  129. $("#clear").click(function() {
  130. $(":input").unautocomplete();
  131. });
  132. });
  133.  
  134. function changeOptions(){
  135. var max = parseInt(window.prompt('Please type number of items to display:', jQuery.Autocompleter.defaults.max));
  136. if (max > 0) {
  137. $("#suggest1").setOptions({
  138. max: max
  139. });
  140. }
  141. }
  142.  
  143. function changeScrollHeight() {
  144. var h = parseInt(window.prompt('Please type new scroll height (number in pixels):', jQuery.Autocompleter.defaults.scrollHeight));
  145. if(h > 0) {
  146. $("#suggest1").setOptions({
  147. scrollHeight: h
  148. });
  149. }
  150. }
  151.  
  152. function changeToMonths(){
  153. $("#suggest1")
  154. // clear existing data
  155. .val("")
  156. // change the local data to months
  157. .setOptions({data: months})
  158. // get the label tag
  159. .prev()
  160. // update the label tag
  161. .text("Month (local):");
  162. }
  163.  
  164. </head>
  165.  
  166.  
  167. <h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/">jQuery Autocomplete Plugin</a> Demo</h1>
  168.  
  169. <div id="content">
  170.  
  171. <form autocomplete="off">
  172. <p>
  173. <label>Single City (local):</label>
  174. <input type="text" id="suggest1" />
  175. <input type="button" value="Get Value" />
  176. <input type="button" value="Change Max Items" onclick="changeOptions();" />
  177. <input type="button" value="Change to Month Data" onclick="changeToMonths();" />
  178. <input type="button" value="Change scroll height" id="scrollChange" />
  179. </p>
  180. <p>
  181. <label>Month (local):</label>
  182. <input type="text" id="month" />
  183. <input type="button" value="Get Value" />
  184. (Current month is excluded from list)
  185. </p>
  186. <p>
  187. <label>E-Mail (local):</label>
  188. <input type="text" id="suggest13" />
  189. <input type="button" value="Get Value" />
  190. </p>
  191. <p>
  192. <label>Single Bird (remote):</label>
  193. <input type="text" id="singleBirdRemote" />
  194. <input type="button" value="Get Value" />
  195. </p>
  196. <p>
  197. <label>Hidden input</label>
  198. <input />
  199. </p>
  200. <p>
  201. <label>Single City (contains):</label>
  202. <input type="text" id="suggest14" />
  203. <input type="button" value="Get Value" />
  204. </p>
  205. <p>
  206. <label>Multiple Cities (local):</label>
  207. <textarea id='suggest3' cols='40' rows='3'></textarea>
  208. <input type="button" value="Get Value" />
  209. </p>
  210. <p>
  211. <label>Multiple Birds (remote):</label>
  212. <textarea id='suggest4'></textarea>
  213. <input type="button" value="Get Value" />
  214. </p>
  215. <p>
  216. <label>Hidden input</label>
  217. </p>
  218. <p>
  219. <label>Image search (remote):</label>
  220. <input type="text" id='imageSearch' />
  221. <input type="button" value="Get Value" />
  222. </p>
  223. <p>
  224. <label>Tags (local):</label>
  225. <input type="text" id='tags' />
  226. <input type="button" value="Get Value" />
  227. </p>
  228. <p>
  229. <label>Some dropdown (&lt;3 IE):</label>
  230. <option value="">Item 12334455</option>
  231. <option value="2">Item 2</option>
  232. <option value="3">Item 3</option>
  233. <option value="4">Item 4</option>
  234. </select>
  235. </p>
  236.  
  237. <input type="submit" value="Submit" />
  238. </form>
  239.  
  240. <p>
  241. <a href="#TB_inline?height=155&width=400&inlineId=modalWindow" class="thickbox">Click here for an autocomplete inside a thickbox window.</a> (this should work even if it is beyond the fold)
  242. </p>
  243.  
  244. <div id="modalWindow" style="display: none;">
  245. <p>
  246. <label>E-Mail (local):</label>
  247. <input type="text" id="thickboxEmail" />
  248. <input type="button" value="Get Value" />
  249. </p>
  250. </div>
  251.  
  252. <button id="clear">Remove all autocompletes</button>
  253.  
  254. <a href="search.phps">PHP script used to for remote autocomplete</a>
  255.  
  256. <h3>Result:</h3> <ol id="result"></ol>
  257.  
  258. </div>
  259. <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
  260. <script type="text/javascript">
  261. _uacct = "UA-2623402-1";
  262. urchinTracker();
  263. </body>
  264. </html>



W moim kodzie brakuje tej zmiennej... nie moge zrozumiec jak powinienem z tego autocomplitera skozytac?
bo gdy wpisuje taki kod to nic nie działa:

[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(function() {
  2. $("input[name='company_name']").autocomplete(base_url+"/shop/bill/client");
  3. });
[JAVASCRIPT] pobierz, plaintext


a metoda client wyswietla dane w takim formacie:
  1. 1|Jan|Kowalski
  2. 2|Andrzej|Nowak
  3. 3|Karol|Przykładowy


a pole na którym chciałbym zrobic wyszukiwanie jest następująco zadelkarowane:
  1. <input type="text" name="company_name" value="" id="company_name" />


Ten post edytował niebieszki 15.02.2011, 15:46:15
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 14.07.2025 - 18:26