JavaScript - Check If A Recordset Exists
Hello,
Quick question for y'all, Using javascript coding, how can you check if a recordset exists? if (rs) { alert("yup the rs is active alright") } this does not work, Any ideas? thanks, Jay Similar TutorialsCan I do something like the below to see if a form exists in a document. Code: if(document.theForm){ alert('form exists'); } Hello, through a javascript injection im trying to find out if a cookie exists on my computer. Here's the code I inject: Code: javascript: if (document.cookie.indexOf('_idp_session') != -1) alert('cookie is here'); else alert('cookie is not here'); and when visiting the options of my browser, I can locate the cookie, and i can see its there. Nevertheless my script keeps telling me its not there.. what am i doing wrong? I'm not entirely sure this is possible. I hope it is, and it doesn't seem to far-fetched or impossible. With JS, how would one go about checking if a user has DivX Web Player installed? Usually people put in code within the embed, so if it the player doesn't load, it would have the message behind stating the fact. However I haven't seen this used at all with DivX, instead, you see pop-up boxes, whether installed or not, stating "Don't have DivX Web Player? Get it here for windows or mac" I find this extremely annoying, and would never want such informalities on my website. I'm using ccs3PIE with my site. What I want to do is check if a DOM element has a css property like border-radius and then add a class to it. The problem I'm having is that I don't know how to check for the css property. I've been searching for it for a couple of hours now and I can't find anything that seems to work. Any ideas? Hey guys..... I found out how you can check if an array value exists but I can't seem to get it to work with the options array for some reason. Any help on how I can find out if a certain select value exists? Thanks! Hello, Really need some help with this code i found online to check to see if a page exists. i am kind of new to Javascript and to have this working would really help me out! Here is the code : Code: <script language="javascript"> var url = "http://www.google.com"; checkUrl(url); function checkUrl(url) { var request = false; if (window.XMLHttpRequest) { request = new XMLHttpRequest; } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHttp"); } if (request) { request.open('GET', url, true); if (request.status == 200) { //FAILING ON THIS LINE ("Unspecified Error") alert ("File does exist"); } } alert("File does not exist"); }</script> It seems to be failing on the .status line and it returns an Unspecified Error in the debugger. I am using IE9 if that makes any difference. I have also tried amending the IF statement to include the readyState == 4, i dont get the error, but it doesn't work as planned. Really appreciate any help. SJG Greetings, If I have a form like so: Code: <form> <input type="text" /> </form> How can I check if the input exists using DOM 0? Code: while (document.forms[0].elements[0].exists){ ...do something } I guess that I could assign a default value and check for something in "document.forms[0].elements[0].value" but that is not the approach I wish to take. I need to loop through all of the elements of a form until there are no more regardless of ID/name/value, am I thinking about this wrong? I'm making a table that is dynamically populated from XML data. One of the columns refers to an XML tag that is NOT required (hence the tag does not exist in every XML entry). How do I write a statement (if, else, or any other?) that says - check for the tag, if the tag exists, write the tag's data, if the tag does NOT exist, write "n/a". Here's the code: Thanks! [CODE] <script type="text/javascript"> if (window.XMLHttpRequest) { xhttp=new window.XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","http://www.mysite.com/file.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; document.write("<table border='0' style='font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#333333; border:#333333 1px solid; text-align:center' cellpadding='5' cellspacing='0'>"); document.write("<tr><td style='border-bottom:#333333 1px solid'><strong>Type</strong></td><td style='border-bottom:#333333 1px solid'><strong>Name</strong></td><td style='border-bottom:#333333 1px solid'><strong>Details</strong></td><td style='border-bottom:#333333 1px solid'><strong>Code<br>(if applicable)</strong></td><td style='border-bottom:#333333 1px solid'><strong>Start Date</strong></td><td style='border-bottom:#333333 1px solid'><strong>End Date</strong></td></tr>"); var x=xmlDoc.getElementsByTagName("link"); for (i=0;i<x.length;i++) { document.write("<tr><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("type")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("code")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("startdate")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("enddate")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> [CODE] Thanks, M8AL Hi All, I am not an expert in Javascript. Can I detect if 1 or more sessions of a website are open? for example, if a session with port 7005 is open like this one below, then I want to assign the next port to this user in the second window of browser http://90.97.8.0:7005/maximo/webclient/login/login.jsp the next IE window should appear like this: http://90.97.8.0:7006/maximo/webclient/login/login.jsp or http://90.97.8.0:7007/maximo/webclient/login/login.jsp Please advise. Thanks Yasar is there a way to do this with javascript ? Code: var fID = document.getElementById('email2'); I'm making a table that is dynamically populated from XML data. One of the columns refers to an XML tag that is NOT required (hence the tag does not exist in every XML entry). How do I write a statement (if, else, or any other?) that says - check for the tag, if the tag exists, write the tag's data, if the tag does NOT exist, write "n/a". Here's the code: [CODE] <script type="text/javascript"> if (window.XMLHttpRequest) { xhttp=new window.XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","http://www.mysite.com/file.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; document.write("<table border='0' style='font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#333333; border:#333333 1px solid; text-align:center' cellpadding='5' cellspacing='0'>"); document.write("<tr><td style='border-bottom:#333333 1px solid'><strong>Type</strong></td><td style='border-bottom:#333333 1px solid'><strong>Name</strong></td><td style='border-bottom:#333333 1px solid'><strong>Details</strong></td><td style='border-bottom:#333333 1px solid'><strong>Code<br>(if applicable)</strong></td><td style='border-bottom:#333333 1px solid'><strong>Start Date</strong></td><td style='border-bottom:#333333 1px solid'><strong>End Date</strong></td></tr>"); var x=xmlDoc.getElementsByTagName("link"); for (i=0;i<x.length;i++) { document.write("<tr><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("type")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("code")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("startdate")[0].childNodes[0].nodeValue); document.write("</td><td style='border-bottom:#333333 1px solid'>"); document.write(x[i].getElementsByTagName("enddate")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> [CODE] Thanks, M8AL Hi There, I need your help. I am capable of getting all the field headers in my excel document but am now unable to get their respective field values. Any idea as to what I am doing wrong? Code: //======================================================================== function v8_export() { //======================================================================== var excel = new ActiveXObject("Excel.Application") var book = excel.Workbooks.Add() var sheet = book.Sheets(1); //sheet.Range("A2").Value = "Hello World" //WRITE COLUMN HEADERS: sheet.Columns("A:P").ColumnWidth = '15' for (var c = 0; c < rs.fields.count; ++c) { sheet.Cells(4, c + 1).Value = rs.fields(c).name } //WRITE FIELD VALUES: var row = 1 for (var c = 0; c < rs.fields.count) { sheet.range('A' + row).value = rs.fields(c).value row = row + 1 } rs.MoveNext excel.Visible = true }//end of function v8_export() Thanks. J Hi There, I really need your help. How could I amend the following code below to incorporate the fieldnames on the top before displaying the values of the recordset? Ie. [FIELDNAME1] [FIELDNAME2] [FIELDNAME3] [FIELDNAME4] value1 value2 value3 value4 Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> <script language="javascript" type="text/javascript"> function getsqltable() { var strtable = "" var cn = new ActiveXObject("ADODB.Connection") var rs = new ActiveXObject("ADODB.Recordset") var dbfile = "imts.mdb" var dbPath = "F:/PROJECTS/IMTS PROJECT/V7/database/" cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + dbPath + dbfile + "") var mySQL = "SELECT * FROM tbl_imts WHERE [File Number] = 'A-2010-00301'" rs.Open(mySQL, cn, 1, 3) rs.MoveFirst strtable='<table cellpadding=0 cellspacing=0 width=75%>'; while (!rs.eof) { strtable+='<tr>'; strtable+='<td>'+rs.fields(0)+'</td>' + '<td>'+rs.fields(1)+'</td>' + '<td>'+rs.fields(2)+'</td>' + '<td>'+rs.fields(3)+'</td>' strtable+='</tr>'; rs.movenext; } strtable+='</table>'; rs.close; cn.close; document.getElementById('htmltable').innerHTML=strtable; } </script> </head> <body> <input type="button" onclick="getsqltable();" value="Click Me"/> <div id="htmltable"></div> </body> </html> I've tried modifying the while code, but it puts it all on one line: Code: while (!rs.eof) { strtable+='<tr>'; strtable+='<td>'+rs.fields(0).Name+'</td>' + '<td>'+rs.fields(1).Name+'</td>' + '<td>'+rs.fields(2).Name+'</td>' + '<td>'+rs.fields(3).Name+'</td>' strtable+='<td>'+rs.fields(0)+'</td>' + '<td>'+rs.fields(1)+'</td>' + '<td>'+rs.fields(2)+'</td>' + '<td>'+rs.fields(3)+'</td>' strtable+='</tr>'; rs.movenext; } any ideas? Much thanks and appreciation for everyones help. Cheers and much thanks in advance, Jay On this webpage http://www.corkdiscos.com/testimonials.html i have a like button. when a user clicks like a comment box appears. when i unlike the button the comment box disappears this is ok but when a user has already liked the facebook page and comes to my webpage the comment box does not show. so im looking for a piece of javascript to check if a user has like the button on my page and if so to show the comment box. please check my source code of the website http://www.corkdiscos.com/testimonials.html to see what i have so far. any help would be greatly appreciated Hi guys. I'm working a bunch of pre existing code on a CMS. Just after a quick fix. Doing a show/hide thing on a particular div somewhere on the page depending if a checkbox is ticked or not. Currently there is 3 checkboxes that are dynamically added through the CMS. Here's simplified version of the form: Code: <form id="simplesearch" name="simplesearch"> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="5" class="input-checkboxes" /> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="4" class="input-checkboxes" /> </form> And here's the javascript I was playing with. Code: function showhidefield(id) { if(document.simplesearch.meta_data_array_search_criteria[custom_profile_type][''].checked) { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "visible"; } else { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "hidden"; } } Problem I'm having is how do i do a check to see if those checkboxes are checked in the javascript with those name arrays? How do i separate them? 'm guessing I have to loop through them or something?Hopefully that make senses - it's late here and I'm losing the plot Any pointers would be gratefully welcomed hi.. I want to have a list of words (in an array or whatever just to work) if the user put that word in a textfield (onblur or onchange) a message popup (alert) appears. (Must be popup alert) but I dont know to code it. HELP! ex.: Code: function badwords() { var badwords = new Array(); badwords =["badwords1","badwords2","AndSo-On"]; if badwords if written in textfield alert("Badwords not allowed"); else nothing happen just continue with next textfield } <input type="text" name="" onBlur=badwords()> Anyone please help I have a script that I had written for me that works in IE (I guess its a ActiveX?) but I display it in the HTML page as the below HTML. I want to be able to tell in Javascript if this object is available in IE Code: <object id="IEPrinterChecker" classid="CLSID:506974F1-EA53-40C6-940A-4A1D47D5934B" width="0" height="0"></object> Listed below you can tell I can check if the plugin is available in Firefox without having to specify in the html the object. How can I do this in IE? Code: <script language="JavaScript"> var plugin; if ( window.ActiveXObject ) { // IE alert("How do I check for the plugin here?"); } else { var type = "application/printer-checker-component;version=1.0.0.1"; // your mimeType if (navigator && navigator.mimeTypes){ var mt = navigator.mimeTypes; for (var i = 0; i < mt.length; i++){ if (mt[i].type == type) { plugin = mt[i].enabledPlugin; if (plugin) break; } } } } if(plugin) { // insert object and/or test the plugin with script alert("plugin is available"); } else { alert("plugin not available or disabled"); } </script> HI all. How do I determine whether a variable exists in a form. I have a form called "theForm". I want to determine whether the variable "THIRD_PARTY" exists in the form and if it has been set. Tracy Hello, I am looking for a way to tell from javascript if a file exists (on the server). I don't mind doing this with a .php script, if I have to, but the javascript still needs to know if the file exists. I thought the following javascript code might work: Code: var file_exists = <?php echo file_exists("OpenTokSessionId.txt"); ?>; but it didn't. PHP parsed the php code, but it didn't assign the result value to the Javascript variable like its supposed to (or at least, it didn't seem to). When I looked at the page source after I uploaded it to the server, that line of code now looked like this: Code: var file_exists = ; Note that my server is setup to pass files with an .html or .htm extension to the php engine. That is why this kind of stuff can be done. But for some reason, php doesn't seem to be able to output bool values. I tried the following .php script, which I loaded directly in my browser, but it didn't output anything: PHP Code: <?php function fileExists() { return file_exists("OpenTokSessionId.txt")) } echo fileExists(); ?> So I changed it to the following, and it outputted "File does not exist.", which is the expected result: PHP Code: <?php function fileExists() { if (file_exists("OpenTokSessionId.txt")) echo "File exists."; else echo "File does not exist."; } fileExists(); ?> |