Prev: GHD limited edition colour collection
Next: FAQ Topic - What does the future hold for ECMAScript? (2010-07-20)
From: Wenguang Wang on 24 Jul 2010 00:32 Hi, My web page has a dynamic combo box which contains some dynamic information queried from the database. Currently I am using php to generate such a page with the dynamic information. However, I want it to be more dynamic: when I click the combo box, before the combo box shows me all options, it should query the database and get the latest results. Otherwise, the user has to manually click the refresh button. Is there a way to achieve such thing using combo box? If not, what control and what technique should I use? Thanks! -Wenguang
From: Alan Gutierrez on 24 Jul 2010 00:47 Wenguang Wang wrote: > Hi, > > My web page has a dynamic combo box which contains some dynamic > information queried from the database. Currently I am using php to > generate such a page with the dynamic information. > > However, I want it to be more dynamic: when I click the combo box, > before the combo box shows me all options, it should query the > database and get the latest results. Otherwise, the user has to > manually click the refresh button. > > Is there a way to achieve such thing using combo box? If not, what > control and what technique should I use? The select element has a DOM interface that allows you to add and remove options. I assume you mean "SELECT" since there is no real combo box in available in the DOM. https://developer.mozilla.org/en/DOM/select To get the information, your going to need to fetch it using XMLHttpRequest. http://www.w3.org/TR/XMLHttpRequest/ Then you'd return JSON from your PHP script and evaluate the response. This would be the way to do it with raw JavaScript. A library like Prototype or jQuery could also be very helpful, but people on this newsgroup do not like them because they leak memory on older browsers. -- Alan Gutierrez - alan(a)blogometer.com - http://twitter.com/bigeasy
From: David Mark on 24 Jul 2010 00:59 On Jul 24, 12:47 am, Alan Gutierrez <a...(a)blogometer.com> wrote: > Wenguang Wang wrote: > > Hi, > > > My web page has a dynamic combo box which contains some dynamic > > information queried from the database. Currently I am using php to > > generate such a page with the dynamic information. > > > However, I want it to be more dynamic: when I click the combo box, > > before the combo box shows me all options, it should query the > > database and get the latest results. Otherwise, the user has to > > manually click the refresh button. > > > Is there a way to achieve such thing using combo box? If not, what > > control and what technique should I use? > > The select element has a DOM interface that allows you to add and remove > options. I assume you mean "SELECT" since there is no real combo box in > available in the DOM. > > https://developer.mozilla.org/en/DOM/select > > To get the information, your going to need to fetch it using XMLHttpRequest. Not necessarily. He could also do script injection (for example). > > http://www.w3.org/TR/XMLHttpRequest/ > > Then you'd return JSON from your PHP script and evaluate the response. Also not necessarily. The X in XHR stands for XML after all. ;) > > This would be the way to do it with raw JavaScript. JavaScript is a trademarked brand name that refers to just one ECMAScript implementations. It would be better to refer to it as "Javascript", "javascript" or simply "JS". And no, I don't mean for legal reasons. > A library like > Prototype or jQuery could also be very helpful, but people on this > newsgroup do not like them because they leak memory on older browsers. > Is that what you got out of the link I cited in that other thread? You need to revisit that one too. Seriously. JFTR, memory leaks are the least of the worries with using either of those two libraries. And it is not that people "on this newsgroup" do not like libraries (though many do not like those two for obvious reasons). One problem arises when posted code veers off into a (sometimes unnamed) library, which makes spotting the problems that much more difficult (if not impossible) And often users of these libraries cannot post a simplified test case as they don't know how to write the equivalent without the library. And yes, many such users storm off in frustration claiming anti- library bias. :)
From: Alan Gutierrez on 24 Jul 2010 01:10 Alan Gutierrez wrote: > Wenguang Wang wrote: >> Hi, >> >> My web page has a dynamic combo box which contains some dynamic >> information queried from the database. Currently I am using php to >> generate such a page with the dynamic information. >> >> However, I want it to be more dynamic: when I click the combo box, >> before the combo box shows me all options, it should query the >> database and get the latest results. Otherwise, the user has to >> manually click the refresh button. >> >> Is there a way to achieve such thing using combo box? If not, what >> control and what technique should I use? > > The select element has a DOM interface that allows you to add and remove > options. I assume you mean "SELECT" since there is no real combo box in > available in the DOM. > > https://developer.mozilla.org/en/DOM/select This will get you started... <html> <head> <script type="text/javascript"> function setSelect() { var select = document.getElementById('menu'); populate(select, [ 'a', 'b', 'c' ]); } function populate(select, items) { select.options.length = 0; for (var i = 0; i < items.length; i++) { select.options[select.options.length] = new Option(items[i]); } } </script> </head> <body onload="setSelect()"> <select id="menu"></select> </body> </html> -- Alan Gutierrez - alan(a)blogometer.com - http://twitter.com/bigeasy
From: Gregor Kofler on 24 Jul 2010 08:52 Am 2010-07-24 06:47, Alan Gutierrez meinte: > http://www.w3.org/TR/XMLHttpRequest/ > > Then you'd return JSON from your PHP script and evaluate the response. > > This would be the way to do it with raw JavaScript. A library like > Prototype or jQuery could also be very helpful, but people on this > newsgroup do not like them because they leak memory on older browsers. This could be *a* reason. For the above problem, say 50 lines of "raw" JS would suffice (the cross-browser issues of XHR are a mild problem at best). In addition one would know what his or her XHR JS routines are doing. Any of the mentioned and not-mentioned libraries heap a bunch of abstraction layers on that along with plenty of unnecessary code. I suppose you already knew that, and just wanted to throw in some trolling comment, to fire up David again. Besides: This memory leaking can be a *real* showstopper. I got involved with a huge project doing some sort of traffic monitoring, polling data via XHR. The customers were *all* on IE and the application was running 24/7. Or rather /should/ run 24/7, since it frequently crashed IE and Win after 10 to 12 hours. The page was ridden with libraries - I can recall jQuery and Spry. Gregor -- http://vxjs.gregorkofler.com
|
Next
|
Last
Pages: 1 2 3 4 Prev: GHD limited edition colour collection Next: FAQ Topic - What does the future hold for ECMAScript? (2010-07-20) |