JavaScript - Check If Form Exists
Can I do something like the below to see if a form exists in a document.
Code: if(document.theForm){ alert('form exists'); } Similar TutorialsHello, 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? 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 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! 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? 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? 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 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. 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 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 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 is there a way to do this with javascript ? Code: var fID = document.getElementById('email2'); hey all - new to the forum, and need some quick help. i have a form with multiple data entry fields, one of which i need to be in a certain format. currently it will only check for total length (17 digits), which is part of it, but the format needs to be exactly: 0000-00000-000000 (where zeros are numbers) the best thing would be if when the user enters 15 digits, it would automatically format it with the dashes. any and all help is appreciated. please note: this is being used for a print solutions software that auto-generates most of the code, we cannot rewrite all of the code, only work with what we have. here is the code: Code: if (Form1.elements['EIF2']){ if(Form1.elements['EIF2'].disabled == false){ if (!CheckEntry('EIF2', 'Lawson # ', true, 17, 'exactly'))return false; } Okay this is part of an ajax driven shopping cart. the problem is i need to check for 2 different selections that would be for the same payment method. here is the code as it sits now Code: if ( typeof document.checkout.payment[3] != 'undefined'){ if (document.checkout.payment[3].checked == true) { if (document.checkout.cc_owner.value == "" ) {errMsg += 'Please complete or verify the information in the Name on the card field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_number.value == "") { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_cvv2.value == "") { errMsg += 'Please complete or verify the information in the CVC/CVV code field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_phone.value == "") { errMsg += 'Please complete or verify the information in the Card company\'s telephone number field in the \'Payment Method\' section.' + "\n"; } else { myCardNo = document.checkout.cc_number.value; myCardType = document.checkout.surcharge.value; if (!checkCreditCard (myCardNo,myCardType)) { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } } } } } }} } the problem is in the first 2 lines i basically need it to do this, but when i do it like how i need it to be it will not work. it looks like i am doing it incorrectly maybe. firebug gives me an undefined error on the first checked value because it does not exist when i need it to check for the 2 value. Code: if ( typeof document.checkout.payment[3] != 'undefined' || typeof document.checkout.payment[2] != 'undefined'){ if (document.checkout.payment[3].checked == true || document.checkout.payment[2].checked == true) { if (document.checkout.cc_owner.value == "" ) {errMsg += 'Please complete or verify the information in the Name on the card field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_number.value == "") { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_cvv2.value == "") { errMsg += 'Please complete or verify the information in the CVC/CVV code field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_phone.value == "") { errMsg += 'Please complete or verify the information in the Card company\'s telephone number field in the \'Payment Method\' section.' + "\n"; } else { myCardNo = document.checkout.cc_number.value; myCardType = document.checkout.surcharge.value; if (!checkCreditCard (myCardNo,myCardType)) { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } } } } } }} } Please help me with this code to determine whether the check box has been checked. I get "Thank you" even if I don't check the check box. <script type="text/javascript"> var uncheck = document.getElementById().checked == false; var accept; function checkAccept() { var uncheck; if (uncheck == false){ alert ("You must accept the terms."); } else (uncheck == true) { alert ("Thank you."); } } </script> <form> <br />Please accept the terms by clicking the box below: <br />Accept terms: <input type="checkbox" id="accept" value="Y" /> <br /><input type="button" name="btn" value="Accept" onclick="checkAccept()" /> </form> </body> </html> I am just starting out using Javascript and created a simple knowledge check to give a learner feedback on a question. It will allow the learner to quickly check if they have mastered a topic. The problem that I am having is that if I put two of these knowledge checks on the same webpage than it just posts the same answer when the submit button is clicked. What I have been doing is just pasting the code below twice on the page and changing the question and answer out. When I click "Check Answer" it is the same answer for both questions. Here is my code: Code: <fieldset> <legend><strong>Question 1</strong></legend> <SCRIPT LANGUAGE="JavaScript"> function readText (form) { TestVar =form.inputbox.value; alert ("You typed: " + TestVar); } function writeText (form) { form.inputbox.value = "The wavelength of the blue light scatters better than the rest, predominates over the other colors in the light spectrum, and makes the sky appear blue to us." } </SCRIPT> <form name="myform" action="" method="GET"> <label for="question">Why is the Sky Blue?</label><br><br> <input name="inputbox" value="" type="text" style="width: 287px; height: 112px"> <p> <input id="question" value="Check Answer" onclick="writeText(this.form)" type="button"> </p> </form> </fieldset> Any help would be much appreciated in terms of direction. Thank you. Hi I have a problem but im not sure if it could be solved by Javascript or PHP but either is good. I have a form with a text box where users can enter a 10 digit code. The 10 digit code can be just numbers/letters (eg. 0123456789 or abcdefghij) or it can be a mixture (eg. 0a1b2c3d4e). What I would like is if the user enters a code which is a mixture of numbers and letters then the submit url goes to mixed.php If the user enters a code which just has letters or numbers then the submit url goes to sole.php Anybody can help me? I know its possible to change the url from selecting radio buttons so I hope this can be achievable. I hope that makes sense...let me know if you need more info. Thanks guys! |