JavaScript - Access Database Using Javascript
Hi,
I want to access SQL database using javascript. I am passing 1 value to the java script but I want to pass that value further to the SQL query as an where clause parameter to retrieve data. If the value retrieves multiple or single data then how do i handle it. Is it possible to use dataset in javascript? Regards, Anthony. Similar TutorialsHello Members. Firstly, I will explain why it is necessary. I am designing a site that will NOT be run from servers and will be accessed directly from a hard drive in a LAN environment only. Therefore no server side scripting is possible. Secondly, the data contained in the database is not important and only contains city names, business line names and team names (i.e. it is simply a way of managing changes to our organizational structure rather than editing 100's of <select> options whenever one of our business lines changes locations). So, my aim is for the JavaScript to grab data from an Access database and then populate a few <select> objects such as: Code: <select name="Site" id="site"> <option>....list of all Sites....</options> <select name="Business Line" id="lines> <option>....list of Business Lines in that Site....</options> <select name="Teams" id="teams> <option>....list of teams in that Business Line on that Site....</options> Here is the connection script that I have so far which is fairly basic: Code: function siteSelect(){ adOpenForwardOnly = 0; adLockReadOnly = 1; adCmdText = 1; var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "C:\AAA Backup\Forms.mbd";Persist Security Info=False"; var ConnectObj = new ActiveXObject("ADODB.Connection"); var adoRecordSet = new ActiveXObject("ADODB.Recordset"); var sql = "SELECT SiteName FROM tblSite;"; this.states = []; ConnectObj.Open(myConnect); adoRecordSet.Open(sql, ConnectObj, adOpenForwardOnly,adLockReadOnly,adCmdText); while (adoRecordSet.EOF != true) { this.states[this.states.length]= adoRecordSet("SiteName").value; adoRecordSet.MoveNext(); } adoRecordSet.Close(); } however, it currently only grabs the site list so I would need additional queries that use variables such as: (this is guaranteed to be completely wrong!) Code: "SELECT lineName FROM tblSite WHERE lineName="siteID.value";"; or is it: Code: "SELECT lineName FROM tblSite WHERE lineName=" + 'siteID.value' + ";"; Not sure. I also have no idea how to actually get the record sets into the visible select objects in the <body>. If any one could offer some suggestions, point me in the direction of some functions or explain a method of accomplishing this task that would be great! Peace. Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. hi, i want to make an ftp access page using javascript i know it's possible using "ftp://" , but when i use this, the browser loads a window with the ftp folder i want a javascript to get ftp access and to give the commands itself any1 who knows how to get ftp access and ability to give file send/receive/... commands with javascript? Hi someone please let me know the way to access a smarty value with javascript? my smarty value is = {$value.url} i want to access it like Code: <script type="text/javascript"> function load() { document.location = '{$value.url}'; } </script> i tried with wrapping code with {literal} {/literal} but it isnt working. can some one correct this please sorry for bad english Thanks Hello everybody, I am new in this forum (and I'm also new in web coding, but not in programming)... This is the first problem I met: I can't understand how to acccess a property in this snippet: Code: function FGGE() { this.totalExternals = 0; this.loadedExternals = 0; this.loadImage = function(image) { image.onload = function() { alert("Loaded 1: "+this.loadedExternals+"/"+this.totalExternals); }; alert("Loaded 2: "+this.loadedExternals+"/"+this.totalExternals); }; } Output is this: Loaded 1: NaN/undefined Loaded 2: 0/0 Could someone help me fixing "Loaded 1"? Thanks a lot Hi all, Have problem from getting data of JavaScript Object ie. Associative Array. Code: var a, table1 a = new ActiveXObject("MyProgID"); a.GetDataFromExcel("C:\\Users\\myFolder\\Desktop\\test.xls","Sheet1") a.Generate() table1 = a.writeInTable(); Here writeInTable function returns a 2D Object array from DLL written in VB.Net. So I got the Object to table1. But from table1, I can't access the values but its there. table1 shows values as in this image(Image Attached.) Actually, I tried many ways like tab(0)(0) tab[0][0] tab["0"] tab.(0).(0) tab.[0].[0] Also with toArray(), (new VBArray(tab)).toArray().... I don't know what I am wrong..Can anyone help me on this? Thanks... Shanmugavel.C This is a question more about an ASP.NET web application, but javascript is involved, so I'm hoping some javascript gurus can assist me. I'm working with a web application that needs to get access to an ASP.NET web control (a button) in javascript. The problen is that since the control is run on the server, javascript can't access it in the standard way (i.e. document.getElementById(controlId); ). I've actually solved this problem before in a different application, but my solution there doesn't seem to work here for some reason. I have this in an aspx file: Code: <script...> ... function myfun() { var b = document.getElementById("<%=SaveButton.ClientID%>"); alert(b); } </script> ... <asp:Button ID="SaveButton" Text="save" OnClientClick="myfun()" ClientIDMode="Static" runat="server" UseSubmitBehavior="False" /> I have a designer class in which the button is declared (and therefore exists in the server-side codebehind): Code: protected global::System.Web.UI.WebControls.Button SaveButton; But when I click on my button, the alert box says "null". Why am I not able to get my button in the javascript function? Some things to note: *The button exists within a content tag: Code: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> *I'm working within Visual Studios 2008. Hi All, I have html pages with code like <div> <script type="text/javascript" src="http://myserver2/mysite/addhtm.js"></script> </div> the script adds some html code and random images selected from second server inside an iframe tag in the div tag. I need to examine this added html and image properties in my page using javascript. A search on internet did not help, it says elements inside iframe coming from different domain can not be accessed. Is there any workaround or hack available to access iframe contents from page javascript? Thanks I am a relative javascript newbie. I wish to detect when a user is leaving a page, and want to know what s/he is doing to leave that page (browser BACK vs. clicked URL), and would like to be able to get this information from the ... document? Where is it held? How can I know this from within my script? Thanks Eric Hi, I'm very new to javascript and I need your help. What I'm trying to do is: I have a html file with javascipt embeded in, in this file I want to use a table object in another javascript file. How do I access this object? Your help is very much appreciated. Regards, lep2 Here is the scenario friends, I have an html page which I load it on a server. I give the URL of this page to my clients. My clients have their digital certificate in their web browsers. There is some data on the html page which is filled by the clients. When the client hits the submit button, a java script should run from behind which should be able to pick up the digital certificate of the client which is laoded on their web browser. This information must be sent along with the data to the server. Is it possible to do this using Java script? Can we access Certificates on a system via Java script? Are there any API calls which can be used in Java script for this purpose? Any help will be appreciated. Thank you for your time. Regards, Rocky I have two servers jboss and ejabbered and i have deployed two html files, one on each as follows: testdirver.html deployed on ejabbered <html><head> <script> function viewmembers() {var w=window.open("http://192.168.56.134:8080/nkms1/kms/test.html");} </script> </head> <body><form name="sub" > <input type="text" id="to" name="to"> <button onClick= "viewmembers();"> </form></body></html> test.html on jboss <html> <script> function abc() {alert(window.opener.document.forms[0].to);} </script> <body onload=abc();></body></html> Problem: window.opener.document gives the js error "Access is Denied" which i am not able to understand. Exchanging the two files on the servers(i.e. testdriver.html on jboss and test.html on ejabbered works fine and i get the output [object]). So i am guessing there is something that has to do with the ejabbered server I am starting a new project soon. Now, the project is still in the stage of planning. But I am quite confuse now which programming language to implement. I am going to design a system where the normal users will update the data with the system while the data required changes will need system administrator to apporve it. I will need a database to keep those records (the data required update) so that the system admin can refer to the database and make changes. Do I have another choice instead of using Microsoft Access 2007 macros or VBA ? I prefer a web-based programming. Any suggestion, please ? Hi, Is is possible to access a global variable for use inside a function? Thanks for help in advance Mike Hi I have developed an internet mapping site which uses an html viewer with various frames to pull in a mapping window, a legend / key and a frame of tools amongst other things. It works absolutely fine in Internet Explorer version 6, but whilst testing it in Internet Explorer 7, my mapping window is not loading up the image. It might seem strange me posting this in a javascript forum but as the error is javascript related I thought I would give it a shot! The error message I am receiving is "Access is denied". After looking online, it appears as though this error could be linked to the use of frames; and those frames trying to access other windows with different document domains?? Does anyone know if new security measures have been implemented in IE7 which restricts the use of frames? My code is below; does anyone notice anything that might give this kind of javascript error? Any help will be greatly appreciated as I do not tend to dable too much in javascript! Code: <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <TITLE>Intranet GIS Service</TITLE> <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript" SRC="javascript/aimsResource.js" TYPE="text/javascript"></SCRIPT> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> // Designer will set the next variable - theTitle //var theTitle = "Intranet GIS"; var theTitle = ""; if (theTitle.indexOf("###TITLE##")!=-1) theTitle = titleList[0]; var cmdString = document.location.search; var webParams = cmdString; var reloadTimer=0; document.writeln("<TITLE>" + theTitle + "</TITLE>"); function doIt() { MapFrame.useJava=false; MapFrame.checkParams(); } function replacePlus(inText) { var re = /\+/g; inText = inText.replace(re," "); return inText; } function reloadApp() { //window.clearTimeout(reloadTimer); //reloadTimer = window.setTimeout("document.location.href = 'viewer.jsp' + cmdString",1000); //Above code replaced with this. Only the map should refresh after a resize, otherwise //all added datashare layers are lost. MapFrame.mWidth = MapFrame.getMapWidth(); MapFrame.mHeight = MapFrame.getMapHeight(); MapFrame.sWidth = screen.width; MapFrame.sHeight = screen.height; MapFrame.loadBannerLeft = parseInt((MapFrame.mWidth - 119)/2); MapFrame.loadBannerTop = parseInt((MapFrame.mHeight - 72)/2); MapFrame.document.getElementById("theMap").style.width = MapFrame.sWidth; MapFrame.document.getElementById("theMap").style.height = MapFrame.sWidth; MapFrame.iWidth = MapFrame.mWidth; MapFrame.iHeight = MapFrame.mHeight; MapFrame.legHeight = MapFrame.iHeight - 160; var cmd = 'MapFrame.sendMapXML();'; cmd += 'MapFrame.document.getElementById("theImage").style.width = MapFrame.mWidth;'; cmd += 'MapFrame.document.getElementById("theImage").style.height = MapFrame.mHeight;'; window.clearTimeout(reloadTimer); reloadTimer = window.setTimeout(cmd,1000); } </SCRIPT> </HEAD> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> var browser = navigator.appName; var moreStuff = 'onresize="reloadApp()"'; var addNS = 0; if (browser=="Netscape") { addNS = 3; } document.writeln('<FRAMESET ROWS="' + (45+addNS) + ',*,30,0" FRAMEBORDER="No" FRAMESPACING="0" onload="doIt()" BORDER=2 ' + moreStuff + '>'); document.writeln('<FRAME NAME="TopFrame" SRC="topbar.htm" MARGINWIDTH="5" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE>'); document.writeln('<FRAMESET COLS="' + (30+addNS) + ',*,270" FRAMEBORDER="No" FRAMESPACING="0" BORDER="2">'); </SCRIPT> <FRAME NAME="TextFrame" SRC="text.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE FRAMESPACING="0" BORDER="2"> <!-- If textframe is used--> <FRAMESET ROWS="*,115"> <FRAME NAME="MapFrame" SRC="MapFrame.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="Yes" RESIZE="YES"> <FRAME NAME="ToolFrame" SRC="blank.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="Auto" FRAMEBORDER="No" RESIZE="YES"> </FRAMESET> <!-- If textframe is not used --> <!--<FRAME NAME="MapFrame" SRC="MapFrame.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" RESIZE="YES">--> <FRAME NAME="TOCFrame" SRC="TOCFrame.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="Auto" FRAMEBORDER="No" RESIZE="YES"> </FRAMESET> <FRAMESET COLS="400,*" FRAMEBORDER="Yes" BORDER=2 FRAMESPACING="0"> <FRAME NAME="ModeFrame" SRC="bottom.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE> <FRAME NAME="ModeFrame" SRC="bottom.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE> </FRAMESET> <FRAME NAME="PostFrame" SRC="jsForm.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE FRAMESPACING="0" BORDER="2"> </FRAMESET> <NOFRAMES> <BODY> <P> </BODY> </NOFRAMES> </HTML> Hello, I am new to javascript, I have been searching how to connect to a database and execute some queries, and then use the data that I get to populate some tables in a web page, all this using javascript. I am confused because I have seen in some webpages that javascript is not designed to connect with databases, and also I have see other pages where they say that it is possible. Does anyone know if it is possible to use javascript to connect to a database (informix), and execute some procedures or queries? Is the any tutorial a about it? Thanks ok this is all hyperthetical and ground work (phishing) for me so any and advice will be warmly welcomed. I would like to start and e-commerce site BUT: I'm sure i should use javascript on client side to validate an order form BUT 1) server side, how is the order revalidated --- ie is javascript used again on server or use of another language? 2) could someone explain how information from order form is connected to an (SQL) database ---- and how is that database then updated? What language is used? (I am talking about the general process here) At the momment i'm researching SQL http://dev.mysql.com/doc/refman/5.5/...ving-data.html and e-commerce database design http://www.princeton.edu/~rcurtis/ul...mdatabase.html but I have no idea how all this is connected and where Javascript finishes and where I need to research further in oreder to put things together. Any help would be fantastic sorry for the novice questions. low tech Okay, I'm good at PHP but using javascript so the user doesnt need to refresh the page is a neat thing. I want to make a button that says "Do you like this game? Yes or No" How can I use javascript to tell Yes to send games->rating_yes = 1 or No games->rating_no = 1 Or if you could link me with resource on building something that can teach me how to use javascript to update/insert into my database. I've tried stuff like this Code: Do you like this game? <a href="javascript://" onclick="ajaxYESorNO('<?=$gameid;?>','like');">Yes</a> or <a href="javascript://" onclick="ajaxYESorNO('<?=$gameid;?>','dislike');">No</a> Code: function ajaxYESorNO(gameid,answer) { ajax = ajaxFunction(); ajax.onreadystatechange = function () { ajaxRateGame_stateChanged(vote); }; var url = base_url+ "includes/ajaxYESorNO.php"; url = url+ "?vote=" +answer; url = url+ "&gameid=" +gameid; ajax.open("GET",url,true); ajax.send(null); } PHP Code: <?php $gameid = $_GET[gameid]; $vote = $_GET[vote]; @include "config.php"; if($_GET['vote']=='like') { $result = $GLOBALS['dFetch']->exec ("update games set rate_yes=rate_yes+1 where gameid = $gameid"); } else { $result = $GLOBALS['dFetch']->exec ("update games set rate_no=rate_no+1 where gameid = $gameid"); } ?> But yet cant seem to figure how to get it working properly Thanks. I'm learning JavaScript, but want to make an accounting program(site) for my brother. It will be backed by php and mysql. I've found that javascript doesn't "really" have multidimensional arrays. The ways I figure to collect name, address, phone, etc could be any of these: 1. Create a customer object (customer.name, customer.address) 2. Use the mutidimensional array that JavaScript does offer. (var customers [ [], [] ]) 3. Create bunches of variables (var customerName, var customerAddress) or any other method I have found (will find). The information will for a customer will be filled out via HTML forms, processed by JavaScript then sent up to the PHP/MySQL database. OR should I just use PHP to deal with these directly? My impression is to use client side technology as much as possible or is this wrong? -Matt Hello All, Forgive me if my terminology is off, as I am a Java and PHP newbie, but i will do my best to explain my problems. I am building a simple site for my job and the HTML and CSS is done. I used a simple PHP script to post form data to an SQL table. I wanted to first create a client side form validator to ensure proper data was being entered into the form (First name, last name, phone, email, state, zip code). Data was being posted to the form no problem prior to the Javascript validation. Now that the Javascript validation is in place, no data is passed to the database and only empty records appear in the table when the form is submitted. How do I get Javascript and PHP to play nicely together? I still need to create a server side validation and also a sanitation script to make sure no one tries to inject malicious code, but my main focus now is making sure data can get posted to the database. Please help me out, and correct any incorrect terminology I'm using. This is my form: Code: <form name="form1" id="form1" "method="post" action="insert.php"> <table width="80%" border="0"> <tr> <td align="right">First Name : </td> <td><input type="text" name="fname" style="width:170px;"></td> </tr> <tr> <td align="right">Last Name : </td> <td><input type="text" name="lname" style="width:170px;"></td> </tr> <tr> <td align="right">Phone : </td> <td class=><input type="text" name="phone" style="width:100px;"> </td> </tr> <tr> <td align="right">Email : </td> <td> <input type="text" name="email" style="width:170px;"></td> </tr> <tr> <td align="right">State : </td> <td><select name="state" style="width:150px;"> <option value="000" selected="selected">Select</option> <option value="Alabama">Alabama</option> <option value="Alaska" >Alaska</option> <option value="Arizona" >Arizona</option> <option value="Arkansas" >Arkansas</option> <option value="California" >California</option> <option value="Colorado" >Colorado</option> <option value="Connecticut" >Connecticut</option> <option value="Delaware" >Delaware</option> <option value="District-of-Columbia" >District of Columbia</option> <option value="Florida">Florida</option> <option value="Georgia" >Georgia</option> <option value="Hawaii" >Hawaii</option> <option value="Idaho" >Idaho</option> <option value="Illinois" >Illinois</option> <option value="Indiana" >Indiana</option> <option value="Iowa" >Iowa</option> <option value="Kansas" >Kansas</option> <option value="Kentucky" >Kentucky</option> <option value="Louisiana" >Louisiana</option> <option value="Maine" >Maine</option> <option value="Maryland" >Maryland</option> <option value="Massachusetts" >Massachusetts</option> <option value="Michigan" >Michigan</option> <option value="Minnesota" >Minnesota</option> <option value="Mississippi" >Mississippi</option> <option value="Missouri" >Missouri</option> <option value="Montana" >Montana</option> <option value="Nebraska" >Nebraska</option> <option value="Nevada" >Nevada</option> <option value="New-Hampshire" >New Hampshire</option> <option value="New-Jersey" >New Jersey</option> <option value="New-Mexico" >New Mexico</option> <option value="New-York" >New York</option> <option value="North-Carolina" >North Carolina</option> <option value="North-Dakota" >North Dakota</option> <option value="Ohio" >Ohio</option> <option value="Oklahoma" >Oklahoma</option> <option value="Oregon" >Oregon</option> <option value="Pennsylvania" >Pennsylvania</option> <option value="Rhode-Island" >Rhode Island</option> <option value="South-Carolina" >South Carolina</option> <option value="South-Dakota" >South Dakota</option> <option value="Tennessee" >Tennessee</option> <option value="Texas" >Texas</option> <option value="Utah" >Utah</option> <option value="Vermont" >Vermont</option> <option value="Virginia" >Virginia</option> <option value="Washington" >Washington</option> <option value="West-Virginia" >West Virginia</option> <option value="Wisconsin" >Wisconsin</option> <option value="Wyoming" >Wyoming</option> </select> </td> </tr><tr> <td align="right">Zip Code: </td> <td><input type="text" name="zcode" style="width:50px;"></td> </tr> <tr> <td> </td> <input type="hidden" name="submitted" value="1"> <td><input type="submit" value="Submit" name="submit"></td> </tr> </table> </form> This is my javascript code that links to an external .js file: Code: <script type="text/javascript"> var frmvalidator = new Validator("form1"); frmvalidator.addValidation("fname","req","Please enter your First Name"); frmvalidator.addValidation("fname","minlen=2","Minimum length for First Name is 2 characters"); frmvalidator.addValidation("fname","maxlen=20","Max length for First Name is 20 characters"); frmvalidator.addValidation("lname","req","Please enter your Last Name"); frmvalidator.addValidation("lname","minlen=2","Minimum length for Last Name is 2 characters"); frmvalidator.addValidation("lname","maxlen=20","Max length for Last Name is 20 characters"); frmvalidator.addValidation("email","req","Please enter a Valid Email Address"); frmvalidator.addValidation("email","maxlen=50"); frmvalidator.addValidation("phone","req","Please enter your 10-digit Phone Number. Example: 5051234567"); frmvalidator.addValidation("phone","minlen=10","Please enter your 10-digit Phone Number. Example: 5051234567"); frmvalidator.addValidation("phone","maxlen=10","Please enter your 10-digit Phone Number. Example: 5051234567"); frmvalidator.addValidation("phone","numeric"); frmvalidator.addValidation("state","dontselect=000","Please select your state"); frmvalidator.addValidation("zcode","req","Please enter your 5-digit Zip Code"); frmvalidator.addValidation("zcode","minlen=5","Please enter your 5-digit Zip Code"); frmvalidator.addValidation("zcode","maxlen=5","Please enter your 5-digit Zip Code"); </script> This is my insert.php file that form uses: PHP Code: <?php $con = mysql_connect("localhost","**********","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sms2011_leads", $con); $sql="INSERT INTO sms2011_prospects (fname, lname, phone, email, state, zcode) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[phone]','$_POST[email]','$_POST[state]','$_POST[zcode]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<script>window.location = 'http://www.nationalcollegesearch.org/thankyou.html';</script>"; mysql_close($con) ?> |