Reputation: 527
I m doing a database project using jsp and javascript and back-end using mysql.
In my GUI,there is a page where when i select a particular item in a textbox .the other textboxes should automatically load other values from the database using the value selected from the first textbox.how can i do this using javascript?
I tried using
obj1=this.options[this.selectedIndex].myvalue
But this did not work.
Upvotes: 2
Views: 2997
Reputation:
javascript is a client-side scripting language .You should use AJAX for access data from Mysql Server.
javascript is used in AJAX
to connect to databases. So what you need is an Ajax
call to the server, retrieve values from database.
Refer : http://www.ajaxmatters.com/2006/05/getting-started-with-ajax-using-java-tutorial/
Upvotes: 1
Reputation: 7027
Javascript is processed by the web browser, and as such doesn't have direct access to your web server as it is done after the user has received the data from your server.
To do as you wish you need to use a server-side language (in your case java as you stated your page is a .jsp)
If you are really dead-set on doing this in Javascript, then node.js may be of assistance, check out http://nodejs.org/ and http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/ however seeing as you are using java to generate your pages this is a bit overkill.
Upvotes: 0
Reputation: 898
In this case your Javascript is running at the client end (Browser). It has no programmatic access to the server. The DB operations can be performed by your Java code and the results can consumed by the Javascript. So what you need is an Ajax call to the server, retrieve values from database, construct a JSON response and return it to the client.
Upvotes: 2
Reputation: 8101
use ajax
to make a server call that will retrieve the values from the database.Its not possible in Javascript alone.
Upvotes: 0