BaRRon
10-22-2003, 10:01 AM
Hi everybody,
I would like to know how to run a sql Server query by the javascript event "onchange" .
BaRRon
I would like to know how to run a sql Server query by the javascript event "onchange" .
BaRRon
![]() | View Full Version : SQL query in javascript function BaRRon 10-22-2003, 10:01 AM Hi everybody, I would like to know how to run a sql Server query by the javascript event "onchange" . BaRRon Shroder 10-22-2003, 01:19 PM I'm not sure if you can do that in the same window. I think you can't but I could be wrong. You could probably create an iframe or have the javascript open a new window and execute the query that way. That would just be a matter of pulling the data from a different window. I haven't tried it myself but I think that's how other sites may be doing it hiryuu 10-22-2003, 04:09 PM Javascript is client-side, so you can't use SQL directly. You would need to have the javascript generate a new http request (as Shroder said, iframe, new window, swapping out an image). The iframe is probably your best hope for retrieving data from the database, since I think js gives you some tools for reading another page. xisp 10-22-2003, 04:24 PM JS isn't my forte but... Since it's client side scripting how would you query the db without giving the world your password? Shroder 10-22-2003, 07:15 PM Doing it with images... hmm... I can't think of how you would do that. I'll have to look into that (or if anyone has any references that would be much appreciated). As far as the password security goes it wouldn't be given out to the whole world because the sql execution is still being handled on the server’s side. Your just passing variables from the main page to the page inside the iframe which will in turn process a php, asp (what ever server side language you use) code and then you could pull the variable(s) from the iframe page into the main page. I'm kind of summarizing it but that is basicaly. And so passwords stay on teh servers side and not the clients. :) On another note, for people who don't understand how everything is working. Please take not in what hiryuu said. It's creating a new HTTP request. I recommend looking into how browsers handle requests if you don't already. hiryuu 10-23-2003, 04:58 AM PHP (asp, cgi) can return any content-type it wishes. You wouldn't really be able to pull data (SELECT), but you could run INSERT, DELETE, or UPDATE queries, and have the script return an image. He didn't really specify what he needed. rrdega 10-23-2003, 08:59 AM <~~ Wouldn't rely on javascript (for anything!) anyway... Too many people disable it in their browsers nowadays. Shroder 10-23-2003, 12:03 PM I think you could actually use data (select) if you scripted it correctly. I know it is done, but I don't know if it is done the way we are talking about here. And I agree, a lot of people disable javascript. Because of that you would have to come up with a scecond non-javscript approach. |