JavaScript - Database Connection With Javascript
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 Similar TutorialsHi all, can anyone tell me why the connection string for the jscript doesn't work but vbscript does? I'm using IE7 only. ------------------------------------ Code Start ----------------------------- <html> <head> <title></title> <script language="vbscript"> Sub GetVBscriptData() Set oADOCon = CreateObject("ADODB.Connection") Set oRecSet = Createobject("ADODB.recordset") oADOCon.ConnectionString = "Provider=SQLOLEDB;Server=PIBDKM894\SQLEXPRESS;Database=SOEAudit;Uid=SOEAuditAdmin;Pwd=password" oADOCon.Open oRecSet.Open "SELECT * FROM Customers", oADOCon sList = "" Do Until oRecSet.EOF sList = sList & oRecSet("NewFirstName") & vbCrLf oRecSet.MoveNext Loop MsgBox sList End Sub </script> <script language="javascript"> function GetJScriptData() { var oADOCon = new ActiveXObject("ADODB.Connection"); var oRecSet = new ActiveXObject("ADODB.Recordset"); var ConnectionString = "Provider=SQLOLEDB;Server=PIBDKM894\SQLEXPRESS;Database=SOEAudit;Uid=SOEAuditAdmin;Pwd=password" ; oADOCon.Open(ConnectionString); oRecSet.Open("SELECT * FROM Customers",oADOCon); var sList = ""; while (!oRecSet.EOF){ sList = sList + oRecSet("NewFirstName"); oRecSet.MoveNext(); } alert(sList); } </script> </head> <body> <input type="button" onclick="GetVBscriptData()" value=" Get some data via vbscript"> <input type="button" onclick="GetJScriptData()" value=" Get some data via javascript"> </body> </html> ------------------------------------- Code End ------------------------------ The error I receive is: Message: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. Line: 26 (opening the javascript connection) I can only presume it's the syntax of the connection string. Any ideas how to alter the string to get it connecting? Thanks in advance, t-racer 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. 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 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 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. I'm integrating a JavaScript typing tutorial to my website. But I'm not able to store the value to the database. In the below code you can see the speed is updated in a html span. The id of the tag is speed(<span id="speed"></span>). This code will automatically update when user start typing. I want to update this to a database when user press submit button. But i cant able to. Is there any way to input the speed to database ? Please go through the below code and suggest me what i can do....? Code: <script type="text/javascript"> //<![CDATA[ var garray = new Array(); var garrayIndex = -1; var gtext = ""; var gindex = 0; var goldPressed = 0; //previous pressed key code var goldTarget = 0; //previous target key code var gtarget = 0; var gpressed = 0; var ggood = 0; var gtotal = 0; var gtime = 0; var gkeytime = 0; function setup() { setEvents(); //change this array to suit your needs but note that indices //must ascend by 1 from 0: garray[0]="foo"; garray[1]="bar";... garray[0] = "a s d f s d f f s d as sd ad fs ds sad af sa fa dafa sda dad das afa sfd add sasd df sf saf dds fd ads safd fsd fas sas dafs as fad"; //more similar lines can easily be added above, dont forget to get the index right! garrayIndex = -1; next(); } function setPatternInit() { //#b note: once we did this using innerHTML but this caused //a leakage of handles in ie var pat = document.getElementById("pattern"); for(; { if (pat.hasChildNodes()) { pat.removeChild(pat.lastChild); } else break; } var cname = "done"; for (j=0; j<gtext.length; j++) { var ch = gtext.charAt(j); if (j>gindex) cname = "future"; else if (j==gindex) cname = "todo"; var kid = document.createElement("span"); kid.className = cname; var txt = document.createTextNode(ch); kid.appendChild(txt); //#b innertext doesnt work on firefox pat.appendChild(kid); } } function setPattern() { var pat = document.getElementById("pattern"); var kids = pat.childNodes; var cname = "done"; for (j=0; j<gtext.length; j++) { if (j>gindex) cname = "future"; else if (j==gindex) cname = "todo"; var kid = kids[j]; kid.className = cname; } } function mapToBoard(code) { if ((code>=97)&&(code<=108)) return (code-32); if ((code>=110)&&(code<=122)) return (code-32); if ((code>=65)&&(code<=90)) return code; if ((code>=48)&&(code<=57)) return code; if ((code==32)) return code; if ((code==44)||(code==46)||(code==47)||(code==59)) return code; return 0; //not on our board picture } function setBoard() { var letter; var elt; var c; var s; if (goldTarget!=0) { c = mapToBoard(goldTarget); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "silent"; elt.className = s; } } if (goldPressed!=0) { c = mapToBoard(goldPressed); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "silent"; elt.className = s; } } if (gtarget!=0) { c = mapToBoard(gtarget); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "target"; elt.className = s; } } if (gpressed!=0) { c = mapToBoard(gpressed); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "pressed"; elt.className = s; } } } function nextPattern() { goldTarget = gtarget; goldPressed = gpressed; if (++garrayIndex == garray.length) garrayIndex = 0; gtext = garray[0]; gindex = 0; gpressed = 0; setPrompt(); } function prevPattern() { goldTarget = gtarget; goldPressed = gpressed; if (--garrayIndex < 0) garrayIndex = garray.length - 1; gtext = garray[garrayIndex]; gindex = 0; gpressed = 0; setPrompt(); } function next() { nextPattern(); setPatternInit(); setBoard(); } function prev() { prevPattern(); setPatternInit(); setBoard(); } function skip(e) { next(); return false; } function back(e) { prev(); return false; } function setEcho(c, isOK) { var s; if (c<' ') c=' '; var s = "["+c+"]"; if (!isOK) s += " ..OOPS!" var elt = document.getElementById("echo"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); } function setPrompt() { var ch = gtext.charAt(gindex); gtarget = ch.charCodeAt(0); } function adjustStatistics(ch) { return; //could count errors by character } function updateSpeed(ok) { var t = (new Date()).getTime(); var dt = (t-gtime); gtime = t; if (dt > 5000) return; //ignore sleepy user gkeytime += dt; var s = (0.5+ggood*60*200/gkeytime).toFixed(0) + ""; var elt = document.getElementById("speed"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); } function updateScore(ok) { if (ok) ggood++; gtotal++; updateSpeed(ok) var s = ggood.toFixed(0) + ""; var elt = document.getElementById("count"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); s = (gtotal-ggood).toFixed(0) + ""; elt = document.getElementById("accuracy"); txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); var s = (gkeytime/1000).toFixed(2) + " s"; var elt = document.getElementById("time"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); } function reset(e) { window.location.reload(); } function debug() { //#b to use, set body onLoad="debug()" instead of "setup()" in html //document.onkeydown=debugKey; //#b document.onkeypress=debugKey; } function debugKey(evt) { //#b var e = (window.event) ? window.event : evt; //#b var k = (e.which)? e.which : e.keyCode; var f = filterKeyCode(k); var s = "k="+k+",f="+f; alert(s); return false; } function setEvents() { //#b document.onkeydown=down; //#b document.onkeypress=press; (document.getElementById('skip')).onmousedown=skip; (document.getElementById('back')).onmousedown=back; (document.getElementById('reset')).onmousedown=reset; } function cleanup() { //pointless, really document.onkeydown=null; //#b document.onkeypress=null; (document.getElementById('skip')).onmousedown=null; (document.getElementById('back')).onmousedown=null; (document.getElementById('reset')).onmousedown=null; } function filterKeyCode(code) { //from key down (0 to ignore) //note: user must have num lock set if they want to use keypad numbers if ((code>=65)&&(code<=90)) return code; //alpha if ((code>=48)&&(code<=57)) return code; //numberic if (code==32) return code; //blank if ((code>=96)&&(code<=105)) return code; //number pad digits if ((code==13)||(code==16)) return code; //enter, shift if ((code>=106)&&(code<=111)) return code; //number pad operators if ((code>=186)&&(code<=192)) return code; //punctuation if ((code>=219)&&(code<=222)) return code; //punctuation return 0; } function filterCode(code) { //from key press as ascii char code (0 to ignore) if ((code==13)||(code==16)) return code; //enter and shift are allowed if (code<32) return 0; if (code>=127) return 0; return code; } function capsLockFilter(e, pressed) { //#b many problems making this cross browser! //#b e.modifiers known only on early mozilla (which does not know standard e.shiftkey)? var shifted = e.shiftKey || (e.modifiers && (e.modifiers & Event.SHIFT_MASK)); //#b var locked = (((pressed > 64) && (pressed < 91) && (!shifted)) || ((pressed > 96) && (pressed < 123) && (shifted))); if (locked) alert("caps lock!"); } function down(evt) { //#b var e = (window.event) ? window.event : evt; //#b var rawcode = (e.which)? e.which : e.keyCode; pressed = filterKeyCode(rawcode); if (pressed > 0) return true; if (typeof(e.cancelBubble)!="undefined") e.cancelBubble = true; if (typeof(e.stopPropagation)!="undefined") e.stopPropagation(); return false; //#b nuisance keys - backspace etc on ie (no effect for capslock!!) } function press(evt) { //#b //#b should work in ie, firefox, safari(hopefully), opera(hopefully) var e = (window.event) ? window.event : evt; //#b var pressed = 0; var wc = -1; var kc = -1; var cc = -1; if (typeof(e.keyCode)!="undefined") kc = e.keyCode; //ie if (typeof(e.charCode)!="undefined") cc = e.charCode; //firefox if (typeof(e.which)!="undefined") wc = e.which; //old mozilla if ((kc>=0)&&(cc>=0)) { //firefox pressed = cc; } else if (kc>=0) pressed = kc; //ie else if (wc>=0) pressed = wc; //old mozilla //alert("pressed="+pressed+",kc="+kc+",cc="+cc+",wc="+wc); pressed = filterCode(pressed); if (pressed==0) { if (kc==13) return skip(); //#b firefox else return false; } if (pressed==13) return skip(); //#b ie capsLockFilter(e, pressed); //hmm var c = String.fromCharCode(pressed); //ie from ascii code var ch = gtext.charAt(gindex); var ok = (c==ch); goldPressed = gpressed; gpressed = pressed; goldTarget = gtarget; if (ok) { gindex++; if (gindex==gtext.length) { if (gtotal-ggood <= 5 && 0.5+ggood*60*200/gkeytime >= 20) { alert('Good work! You had fewer than 5 errors and typed faster than 20 WPM! Now try the next exercise!'); setPatternInit(); } else if (gtotal-ggood > 5 && 0.5+ggood*60*200/gkeytime >= 20){ alert('Good speed! You were over 20 WPM but have more than five errors! Slow down a bit for accuracy.') setPatternInit(); } else if (gtotal-ggood <= 5 && 0.5+ggood*60*200/gkeytime < 20){ alert('Good accuracy! You had fewer than 5 errors, now try for 20 WPM.') setPatternInit(); } else alert ('Focus on accuracy first, then go for speed!'); setPatternInit(); } else setPattern(); gpressed = 0; setPrompt(); setEcho(c, true); updateScore(true); } else { setEcho(c, false); updateScore(false); setPattern() } setBoard(); return false; } //</XMLCDATA> </script> This is my HTML Code : Code: <body onload="setup()" onunload="cleanup()"> <div id="container1"> <div id="container3"> <div id="body"> <div id="pattern" class="big"> </div> <div id="prompt" class="prompt"> </div> <div id="board" class="board"> <div id="row0" class="row0"> <span id="code49">1</span> <span id="code50">2</span> <span id="code51">3</span> <span id="code52">4</span> <span id="code53" style="margin-left:-5px;">5</span> <span id="code54">6</span> <span id="code55">7</span> <span id="code56">8</span> <span id="code57">9</span> <span id="code48">0</span> </div> <div id="row1" class="row1"> <span id="code81">Q</span> <span id="code87">W</span> <span id="code69">E</span> <span id="code82" style="font-weight:bold">R</span> <span id="code84">T</span> <span id="code89">Y</span> <span id="code85" style="margin-left: -2px;">U</span> <span id="code73">I</span> <span id="code79">O</span> <span id="code80">P</span> </div> <div id="row2" class="row2"> <span id="code65">A</span> <span id="code83">S</span> <span id="code68">D</span> <span id="code70" style="font-weight:bold;">F</span> <span id="code71" style="margin: 0 0 0 -5px;">G</span> <span id="code72">H</span> <span id="code74" style="font-weight:bold;">J</span> <span id="code75">K</span> <span id="code76">L</span> <span id="code59">;</span> </div> <div id="row3" class="row3"> <span id="code90">Z</span> <span id="code88">X</span> <span id="code67">C</span> <span id="code86" style="font-weight:bold">V</span> <span id="code66">B</span> <span id="code78">N</span> <span id="code77" style="font-weight:bold">M</span> <span id="code44">,</span> <span id="code46">.</span> </div> <div id="row4" class="row4"> <span id="code32">[SPACE]</span> </div> <div id="scores"> <div class="count">Characters: <span id="count"></span> </div> <div class="accuracy">Errors: <span id="accuracy"></span> </div> <div class="speed">WPM: <span id="speed"></span> </div> <div class="time">Time: <span id="time"></span> </div> </div> <div align="center"> <button id="reset" class="button123" name="reset" align="center">Restart Exercise</button> </div> </div> <div id="echo" class="echo" style="display:none;"> [] </div> <div style="display:none;"> <button id="skip" class="button123" name="skip">skip</button> to next line ("enter" key is shortcut) </div> <div style="display:none;"> <button id="back" class="button123" name="back">back</button> to previous line </div> </div> </div> Hello Everyone, I am using Javascript in ASP page to connect to the database. I am not able to figure out where is the problem. Gettting this error-> Quote: Error Type: Microsoft OLE DB Provider for SQL Server (0x80004005) [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. /MyWeb/test.asp, line 9 My code is-> Code: <%@ Language = JavaScript %> <% var myconnection var myrecordset var connectionString myconnection = Server.CreateObject("adodb.connection") connectionString = "Provider=SQLOLEDB.1;Password=myPwd;Persist Security Info=True;User ID=myId;Initial Catalog=MyTable;Data Source=MyCompName\MyDBINSTANCE" myconnection.Open(connectionString, myconnection); %> If someone could please guide me in the right direction I would greatly apprieciate it. Thanking You. I cant get the right outputs when the user enters invaild information please help! Code: <body> <script language="javascript"> // database goes here var username = new Array(3); username[0]="mary"; username[1]="john"; username[2]="kevin"; var password = new Array(3); password[0]="poppins"; password[1]="doe"; password[2]="poppins"; function Authenticate() { // read the values from the form in the following variables var name = document.getElementById("username").value; var pass = document.getElementById("password").value; var j; //check the username and password against our database for(i = 0; i < 3; i++) { if(name == username[i]) { j = 1; } else if(pass == password[i]) { j = 1; } else { j = 0; } // output the appropriate message in the output Text Box. } if(j = 1) { document.getElementById("output").value = "correct login information"; } else if(j = 0) { document.getElementById("output").value = "incorrect login information"; } } </script> <form name="form1"> Username : <input name="username" type="text"><br><br> Password : <input name="password" type="password"><br><br> <input type="button" value="submit" onClick="Authenticate();"><br><br> Output : <input name="output" type="text"> </form> Hello, I am trying to get the HTML 5 database that is supposed to work with safari up and running... I am following the instructions here, http://developer.apple.com/safari/li...tDatabase.html. I copied and pasted the first three code examples (to build the db, add a table to the db, and request from the db's table.) It is creating a database in my database folder (on my mac, and my iphone) but it does not create a table, and when I try to retrieve from the table, I get the message that the table doesn't exist.... Any ideas? I am lost. 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) ?> I'm attempting to modify a facebook app I purchased that allows friends to send gifts to each other. The problem with the program is that when gifts are accepted, they continue to show on the "accept gift" page. I'd like to change it so that after gifts are accepted, they no longer show on that page, preventing the user from wondering "which gifts have I already accepted?" Later, I'd like to also create a reject gift option, but 1st things 1st. The program is written in php, html, and javascript. I decided one solution was to add a new empty column to the sql table called "accepted". When the user presses "accept gift" I'm thinking an onclick event could be used to add a "y" (for yes) to that record in the database. Then modify the code that displays the gifts to only show gifts from the table 'WHERE' accepted is equal to null. My questions a Is this a logical approach? If so, is the process: create a javascript function that updates mysql and call that function with an onclick event? What about sql injection vulnerabilities? I've read a lot about ajax and HTTP request being the way to do things like this, but could not find an example that represented what I want to do. After weeks of reading, I'm still lost. Hello to all, I am new to JavaScript, I need a javascript/html code for connecting CouchDB database, reading the content from couchdb database and displaying in the browser window. Please help me, Thanks, Nandha. hi, im fairly new to javascript but i know the basics. im just wondering is there a possibility to make a search that will connect to my databse with a product list in it, and then display any matches to what the user searched for? help is always helpful Below, I added: bmiresult to my database but I get the error: There has been an error: could not prepare statement (1 table bmical has no column named bmiresult) Code: html5rocks.webdb.createTable = function() { var db = html5rocks.webdb.db; db.transaction(function(tx) { tx.executeSql("CREATE TABLE IF NOT EXISTS bmical(ID INTEGER PRIMARY KEY ASC, height1 INTEGER, weight1 INTEGER, added_on DATETIME, bmiresult INTEGER)", []); }); } html5rocks.webdb.addTodo = function(todoText) { var db = html5rocks.webdb.db; db.transaction(function(tx){ var weight1 = document.getElementById("weight1").value; var height2 = todoText / 100 var BMI = weight1 / (height2 * height2) var BMI = BMI; var bmiresult = BMI.toFixed(3); var addedOn = new Date(); tx.executeSql("INSERT INTO bmical(height1, weight1, added_on, bmiresult) VALUES (?,?,?,?)", [todoText, weight1, addedOn, bmiresult], html5rocks.webdb.onSuccess, html5rocks.webdb.onError); }); } Hello. I have a problem here I have this menu: Code: <script language="JavaScript"> <!-- function mmLoadMenus() { if (window.mm_menu_0516213335_0) return; window.mm_menu_0516213335_0 = new Menu("root",160,18,"Verdana, Arial, Helvetica, sans-serif",12,"#000000","#ffffff","#f7c68c","#214a6b","center","middle",3,0,1000,-5,7,true,true,true,0,false,true); mm_menu_0516213335_0.addMenuItem("Item5","location=''item5.html'"); mm_menu_0516213335_0.addMenuItem("Item6","location=''item6.html'"); mm_menu_0516213335_0.hideOnMouseOut=true; mm_menu_0516213335_0.menuBorder=2; mm_menu_0516213335_0.menuLiteBgColor='#294a63'; mm_menu_0516213335_0.menuBorderBgColor='#102939'; mm_menu_0516213335_0.bgColor='#101008'; window.mm_menu_0506211449_0 = new Menu("root",160,18,"Verdana, Arial, Helvetica, sans-serif",12,"#000000","#ffffff","#f7c68c","#214a5a","center","middle",3,0,1000,-5,7,true,true,true,0,false,true); mm_menu_0506211449_0.addMenuItem("Item1","location='item1.html'"); mm_menu_0506211449_0.addMenuItem("Item2","location='item2.html'"); mm_menu_0506211449_0.addMenuItem("Item3","location='item3.html'"); mm_menu_0506211449_0.addMenuItem("Item4","location='item4.html'"); mm_menu_0506211449_0.hideOnMouseOut=true; mm_menu_0506211449_0.menuBorder=2; mm_menu_0506211449_0.menuLiteBgColor='#294a63'; mm_menu_0506211449_0.menuBorderBgColor='#102939'; mm_menu_0506211449_0.bgColor='#101008'; mm_menu_0506211449_0.writeMenus(); } // mmLoadMenus() function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> <script language="JavaScript1.2">mmLoadMenus();</script> And I have a database with 3 fields: id, name and contents. These are the pages. Basically I want to do a select on the mysql database using PHP and populate the menu from the database. Can you tell me how to do this? Thanks Hi, Using the following javascript: Code: <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"> </script> <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/USERNAME.json?callback=twitterCallback2&count=1"> </script> I am able to display the latest tweet of a user into a div. However, I have a user-generated database of username's stored in an XML file and would like to list each username's latest tweet on a single page. Any thoughts on how I might be able to achive this? I'm new to javascript so forgive my stupidity. i have pasted below java script code. please check write or wrong <script language = "JavaScript" type="text/javascript"> // Remove down to "ConnectionSpeed Detection section" if you don't want to use cookies // If you drop a cookie it can be picked up on return by php or something else function setCookie(name, value, expire) { document.cookie = name + "=" + escape(value) + ((expire == null ? "" : (";expires=" + expire.toGMTString()))); // alert('A cookie called '+name+' is now set with value: '+value); //enable to alert user of cookie } function getExpireDate() { var expires = new Date(); expires.setTime((new Date().getTime() + 1000 * 60 * 60 * 24 * 365)); return expires; } // ConnectionSpeed Detection section var datasize = 31468; // Size of data being transferred, in Bytes var startTime = 0; var endTime = 0; var date = 0; var ctype = ""; var textMessage = ""; function calcThroughput() { var diffTimeMilliseconds = endTime - startTime; var diffTimeSeconds = diffTimeMilliseconds / 1000; var bits = (datasize * 8); // convert Bytes to bits, var kbits = bits / 1024; // convert bits to kbits var throughput1 = kbits / (diffTimeSeconds * 100 / 100); throughput = throughput1 * .93; // account for IP packet header overhead - averages about 7% setCookie("MediaThroughput", throughput, getExpireDate()); // Remove to not use cookie if (throughput < 185) { ctype = "Home.aspx"; } if (throughput > 185) { ctype = "intro.aspx"; } textMessage = "Bandwidth: <B>" + ctype + "</B><br>time to load: (sec): <B>" + diffTimeSeconds + "</B><BR>kbits loaded:<B> " + kbits + "</B><BR>Throughput (kbps): <B>" + throughput + "</B>" document.location = ctype; } </script> <script language = "Javascript" type="text/javascript"> <!-- A bunch of binary data here in the actual file --> </script> </head><body> <script language = "Javascript" type="text/javascript"> date = new Date(); endTime = date.getTime(); calcThroughput(); </script> automatic detect default page and check to low band version go to html page or high band version go to flash page. please help!!!!!!!!!!!!!!!!!!!!!!!!! I am trying to figure out a way to have a page redirect if the mysql connection fails. The issue is that the page is already loaded and the only time this would be needed is if the user tries to perform operations on a loaded page after the session runs out. So basically, I have a page that will allow you to search for an item using ajax, then select an item and press add which will place the item in another table displaying detailed information. Both operations connect to the database using SESSION variables to save the connection information. My goal is to use the "or die()" method to print something that will force a redirect because this could happen in a number of places in the site and I want to try and get them all in one swipe. Here is what seemed like it would be the most promising: Code: $conn = mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password']) or die("<script>location.href= '../login.php'</script>"); Unfortunately the javascript never runs.... I tried putting alerts also and nothing, but with firebug I can see they are printed. Any idea how I can ensure that the javascript is executed? Thanks in advance. In the home page (index.html) i have a flash intro. The first time a user sees the website, the intro should play. Once he goes to another page (about_us or contact_us) and comes back to the home page, it should show a different swf (the version without the intro) - i have created two swf files. I need to know how to change them when the user has already seen the intro or was in the home page before. When i googled, i found something on cookies. I have no clue on how to set them and change the swf file. Would be great if someone has already done this or point me to a tutorial. i need java script. please help!!!!!!! i need script will detect connection speed and redirect to a page:
|