| | |
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
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar cart checkbox child class codes column cookies createrange() css cursor date debugger decimal design dom download dropdown editor element enter error explorer file firefox focus forms frameworks getselection google gwt html htmlform ie8 iframe images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent php player post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select session shopping size sql text textarea toggle variables w3c web website window windowofwords windowsxp wysiwyg \n





