| | |
How to query database through javascripts
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
Hi,
I don't know much about javascripts. I am preparing a module in PHP in which I have to validate data entered by a user through javascripts. Now there is a field in which I have ensure that the value entered by the user already resides in the database. How could I achieve this?
I don't know much about javascripts. I am preparing a module in PHP in which I have to validate data entered by a user through javascripts. Now there is a field in which I have ensure that the value entered by the user already resides in the database. How could I achieve this?
Commitment is what transforms a promise into reality. It is the words that speak boldly of your intentions. And the actions which speak louder than the words. It is making the time when there is none. Commitment is the stuff character is made of; the power to change the face of things. It is the daily triumph of integrity over skepticism.
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Solved Threads: 0
First you have to make a script in PHP to query the database with the value passed from the script below and then give an output in the script by using either print or echo. In the page that you want to pass the value back to the script you need to add the following....
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript1.2" type="text/javascript"> function makeRequest(url) { var httpRequest; if (window.XMLHttpRequest) { // Mozilla, Safari, ... httpRequest = new XMLHttpRequest(); if (httpRequest.overrideMimeType) { httpRequest.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!httpRequest) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } httpRequest.onreadystatechange = function() { alertContents(httpRequest); }; httpRequest.open('GET', url, true); httpRequest.send(''); } // Function to deal with returned request function alertContents(httpRequest) { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { changeText(httpRequest.responseText); //alert(httpRequest.responseText); } else { alert('There was a problem with the request. '+httpRequest.status); } } } Then with is in the page you only have to make your own function in JS to deal with the reply back from your script on the webserver. function changeText(){ // This is were you put your script to handel if it is the same or not. } </script>
Last edited by Tekmaven; Jul 17th, 2008 at 1:33 pm. Reason: Code tags
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: how to display only checked value in checkbox by using javascript?
- Next Thread: newbie coping the data in html field
Views: 707 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child close codes date debugger decimal dependent developer disablefirebug dom element embed engine enter events ext file firefox flash focus form forms frameworks game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index java javascript javascripthelp2020 javascripts jquery jsp jump libcurl listbox maps marquee masterpage math media menu mp4 onerror onmouseoutdivproblem onmouseover onreadystatechange paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star starrating stretch synchronous toggle tweet unicode variables web webkit webservice window \n





