JavaScript - Run Server Side Script From Javascript
Similar TutorialsHi people, I need help as follows: On the server side I have a php generated session parameter. I need to pass it to javascript on the client side page. I saw on the web the following solution: <script language="JavaScript"> var mySessionVar="<%= Session["MySessionVar"] %>"; </script> I tried it but it did not work. I could not find any explanation of this syntax - will appreciate one. Any suggestions, maybe in another way? Thanks Hi all, I would like to have an HTML button which, when clicked by the user, contacts the server and runs a Python script on the server. When the Python script finishes running, the current HTML page automatically reloads a file from the server. Is that possible? YJ I would like to use functionality similar to DirectoryInfo and FileInfo using server-side javascript in ASP.NET, but neither are recognized. What are the equivalents, if they exist, in javascript?
I'm attempting to pull the hidden iframe file upload trick using javascript. I've go my form file upload and iframe fine, but I can't figure out what to do when it gets server side. There seems to be relatively no documentation on how to handle uploaded files in server-side javascript. Ideas? I'm at a loss.
Hi, I have a script that writes to an IFRAME, it writes dynamically and then needs to reload it server side. Anybody knows how to do it? I'm joining the code of my attempt but it appears to be reloading the IFRAME on the client side therefore causing an activeX error since I am running this in FireFox: PHP Code: var frTraductionID = document.getElementById("frTraduction"); frTraductionID = (frTraductionID.contentWindow) ? frTraductionID.contentWindow : (frTraductionID.contentDocument.document) ? frTraductionID.contentDocument.document : frTraductionID.contentDocument; var x=frTraductionID.document.getElementById("hCount").value; var ifrm = document.getElementById("ifUPDATE"); ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument; ifrm.document.open(); ifrm.document.write('<scr' + 'ipt language=javascript type="text/javascript" runat=server>'); ifrm.document.write('var fso = new Active' + 'XObject("Scripting.FileSystemObject"); '); ifrm.document.write('var f = fso.OpenTextFile("' + sFileName + '", 2, true); '); for (var i=0;i<x;i+=1) { var sString=""; sString +="f.WriteLine('"; sString +=frTraductionID.document.getElementById("h"+i).value; sString +='="'; sDetail=frTraductionID.document.getElementById("d"+i).value.replace('"', ' '); sDetail=sDetail.replace("'", "`"); sString +=sDetail; sString +='"'; sString +="')"; sString +="; "; alert("i = " + i + " str = " + sString); ifrm.document.write(sString); } ifrm.document.write("f.Close();"); ifrm.document.write("</Scr" + "ipt>"); ifrm.document.close(); document.getElementById('ifUPDATE').contentWindow.location.reload(true); any help would be appreciated. Hi, I have created a global navigation includes document. Unfortunately the drop down menus that are part of the navigation aren't working. They worked fine when they were part of the page, but now that they are separated from the page as includes the drop down menus don't appear in my test site (posted to a web server). All other content in the includes file appears and works. Any ideas? Thanks for your help. Hi guys, I need your expertise regarding my dilema. I was able to create a simple google map html page at our web server, this web server has access to the internet. the problem is, when this page is accessed from a different PC that has no internet access, the google map won't work. I know that javascripts are run at the client side, so i'm asking is it possible to run everything at the server, including the javascripts and still output the google map? i used this tutorial to make my google map page : http://googlemaps.mayzes.org/ I have a form field that needs to be validated in a hidden Iframe which is driven by Coldfusion. Which is working fine. But the same form field also need do some client side validation as well if Server side (iframe) validation passes. I thought I could create a javascript function, in it call a server side validate and then client side, but without any success. It does not process in the order as expected. Javascript always go first, then the server side validation. I tried to delay the client side with time delay, then server side did process first, but client function could not recognize the parameter passed. here is the function: Function doValidation(param1,param2,param3,param4) { .... document.iframName.src='serverValidate.cfm?m1=param1&p2=param2'; .... clientValidate(param3,param4); } If only I could have serverside validation return a value the function, then I could defined that value then the the clientValidate(param3,param5) to start other wise warn with a message. Both validation does work seperately. The issue is it triggered by one onChange event I have to put them in one function. Maybe I am on a wrong track. Please advise if anyone could have better solution. Thanks in advance. JT Hello again... I have written a custom slideshow script which gets the images from an array... The script will change the src of a img, which is a fullscreen background. Now here's the problem, I've been trying to write a function where can define a folder "gallery\test\", and then get all image files in that folder and repopulate the slideshow array. So, is there a way to scan folders? I've searched around and found some solutions where PHP is used, but i really want to keep this pure js, if possible (?) Thanks, I have the following JavaScript (see below). The script requests an XML file from the server and displays it on the page. The script works fine when the requested XML file is stored on the same server as the script. The problem is when I try requesting an XML file from an external server such as the National Weather Service. I get an error. If I take the XML file from the National Weather Service and save it to my server it works. Why can't I use my script to request XML files stored on external servers? Thanks in advance for any help. Javascript Code Code: window.onload = initAll; var xhr = false; function initAll() { document.getElementById("makeTextRequest").onclick = getNewFile; document.getElementById("makeXMLRequest").onclick = getNewFile; } function getNewFile() { makeRequest(this.href); return false; } function makeRequest(url) { if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (xhr) { xhr.onreadystatechange = showContents; xhr.open("GET", url, true); xhr.send(null); } else { document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest"; } } function showContents() { if (xhr.readyState == 4) { if (xhr.status == 200) { if (xhr.responseXML && xhr.responseXML.contentType=="text/xml") { var outMsg = xhr.responseXML.getElementsByTagName("choices")[0].textContent; } else { var outMsg = xhr.responseText; } } else { var outMsg = "There was a problem with the request " + xhr.status; } document.getElementById("updateArea").innerHTML = outMsg; } } HTML Code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My First Ajax Script</title> <script type="text/javascript" src="script01.js"></script> </head> <body> <p><a id="makeXMLRequest" href="http://www.weather.gov/xml/current_obs/KOJC.xml">Request an XML file</a></p> <div id="updateArea"> </div> </body> </html> I have a form that I've made in the XHTML comprised of text boxes and radio buttons. I want to put a button on the page that when clicked, takes the values in the data, processes it client-side and then outputs it to the same page that it took the data from. I'm having difficulty know exactly how to reference the data in each form element. So far, it seems like I can use getElementById, but my efforts so far have stymied me. The code is this: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>QuadWay DomQuote</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <!-- external script declarations --> <script type="text/javascript" src="chkValidityOfNumber.js"></script> <script type="text/javascript" src="calcQuote.js"></script> <script type="text/javascript" src="calcGoodsAndServicesTax.js"></script> <script type="text/javascript" src="calcTotalCostIncludingGST.js"></script> <script type="text/javascript" src="outPutResultsToPage.js"></script> </head> <body> <form action="" name="quadway"> <!-- create fields to enter customer details into --> <b>Customer Details</b> <p>Customers Full Name: <input type="text" id="customersfullname" name="custName" /> </p> <p>Contact Telephone Number: <input type="text" id="customerstelephonenumber" name="phoneNumber" /> </p> <p>Customers Address: <textarea id="customersaddress" name="custAddress" cols="20" rows="5"></textarea> </p> <hr /> <!-- create fields to enter the regularity of service --> <b>Regularity</b> <p> <input type="radio" name="regularity" value="1" /> Once only </p> <p> <input type="radio" name="regularity" value="4" checked /> Weekly </p> <p> <input type="radio" name="regularity" value="2" /> Fortnightly </p> <p> <input type="radio" name="regularity" value="1" /> Monthly </p> <hr /> <!-- create radio buttons to select the contract period --> <b>Contract Period</b> <p> <input type="radio" name="contractperiod" value="1" /> N/A (Once Only) </p> <p> <input type="radio" name="contractperiod" value="6" /> Six Months </p> <p> <input type="radio" name="contractperiod" value="12" /> One Year </p> <p> <input type="radio" name="contractperiod" value="24" /> Two Years </p> <hr /> <!-- create radio buttons to select the type of service --> <b>Type</b> <p> <input type="radio" name="typeOfService" value="1" /> Standard </p> <p> <input type="radio" name="typeOfService" value="1.4" /> Premium </p> <hr /> <!-- create fields to enter how many bedrooms, living areas and service areas there are and their area --> <b>Bedrooms</b> <p>Number of bedrooms: <input type="text" name="numBedrooms" size="3" maxlength="3" onchange="return chkValidityOfNumber(this)" /> </p> <p>Area: <input type="text" name="areaBedrooms" size="3" maxlength="3" onchange="return chkValidityOfNumber(this)" /> m2 </p> <b>Living Areas</b> <p>Number of living areas: <input type="text" name="numLivAreas" size="2" maxlength="3" onchange="return chkValidityOfNumber(this)" /> </p> <p>Area: <input type="text" name="areaLivAreas" size="3" maxlength="3" onchange="return chkValidityOfNumber(this)" /> m2 </p> <b>Service Areas</b> <p>Number of service areas: <input type="text" name="numServAreas" size="2" maxlength="3" onchange="return chkValidityOfNumber(this)" /> </p> <p>Area: <input type="text" name="areaServArea" size="3" maxlength="3" onchange="return chkValidityOfNumber(this)" /> m2 </p> <input type="button" name="calculateQuoteButton" value="Calculate Quote" onClick = "calcQuoteBeforeTax(this.form)"></input> var theForm=document.getElementById("quadway"); <input type="button" name="tester" value="test" onClick = "alert(document.quadway.getElementById.elements[0].value);"></input> </form> <hr /><hr /> <b>Quote</b> </body> </html> Right down the bottom, under the word 'Quote is where the output should go. Any suggestions on how to do this? Regards Jenny I know that Javascript is client side, but I'd like to know the best way to populate HTML drop downs in real time based on information typed in the other HTML form fields with information found on the server as opposed to the client. For instance if a user wants to select certain files located in a directory on the server, as they type in the pathname supposedly containing the files the drop downs continually refresh themselves with the server files listed in that directory (if it exists, and apache has permissions to see what's inside) as if it was showing client files instead. What would be nice is if my browser could continually query the server for some of its private information and not have to refresh itself to obtain it, whether that means the server-side would have to continually refresh itself makes no difference to me as long as the client-side doesn't have to. But I guess this is not possible because no matter what you would have to at least refresh the client-side page once? Submitting the form to a CGI or PHP script would not work because I need this functionality to help populate the form BEFORE I send it. I would like to not have to press a button to update the form every time I change the pathname and need to update the drop downs since this would be annoying. I'm open to anything that could do this or something similar not just Javascript. I'm not sure if you could accomplish this by converting the HTML page to CGI/PHP and having it continually reload itself without refreshing the page? I'm not worried about any security risks this may pose because: 1) The server is located on company intranet which is firewalled 2) I could always password protect and encrypt all transmissions, making sure only authorized users use the app I wish to change the dynamic text in a javascript to that which is in a MySQL database using PHP. this is then used in a flash scroller. currently i have hard coded the text in the javascript file. is there a way to have PHP run in the javascript file before it is sent to the endusers? or another way ? Hi, The following code is not working whose purpose is to validate the form with javascript. Please Help . Code: <html> <head> <script type='text/javascript'> function formValidator() { // Make quick references to our fields var firstname = document.getElementById('firstname'); var addr = document.getElementById('addr'); var zip = document.getElementById('zip'); var state = document.getElementById('state'); var username = document.getElementById('username'); var password = document.getElementById('passwd'); var email = document.getElementById('email'); var cpassword=document.getElementById('pass2'); var txtar=document.getElementById('ta'); var rad=document.getElementById('r1'); var cbox =document.getElementById('r1'); // Check each input in the order that it appears in the form! if(isAlphabet(firstname, "Please enter only letters for your name")) { if(isAlphanumeric(addr, "Numbers and Letters Only for Address")) { if(isNumeric(zip, "Please enter a valid zip code")) { if(madeSelection(state, "Please Choose a State")) { if(lengthRestriction(username, 6, 8)) { if(plengthRestriction(password,4,6)) { if(confpass(cpassword,"Please confirm")) { if(emailValidator(email, "Please enter a valid email address")) { if(istextareablank(txtar,"Please enter some text")) { if(isradiobuttselected(rad,"Please select any one radio buttons")) { if(ischeckboxselected(cbox,"Please select at least one checkbox")) { return true; } } } } } } } } } } } return false; } function notEmpty(elem, helperMsg){ if(elem.value.length === 0){ alert(helperMsg); elem.focus(); // set the focus to this input return false; } return true; } function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphanumeric(elem, helperMsg){ var alphaExp = /^[0-9a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function lengthRestriction(elem, min, max) { var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter username between " +min+ " and " +max+ " characters"); elem.focus(); return false; } } function plengthRestriction(elem, min,max) { var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter password between " +min+ " and " +max+ " characters"); elem.focus(); return false; } } function madeSelection(elem, helperMsg){ if(elem.value == "Please Choose"){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } function emailValidator(elem, helperMsg){ var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; if(elem.value.match(emailExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function confpass(elem,helperMsg) { if ( confPasswd === "" ) { alert("Please fill in the Confirm Password"); document.forms[0].elements[7].focus( ); return false; } else if (document.forms[0].elements[6].value != document.forms[0].elements[7].value) { alert( "Your passwords do not match. Please retype and try again."); return false; } } function isEmpty(s) { return ((s === null) || (s.length === 0)); } function istextareablank(elem,helperMsg){ var i; <!-- Is empty? --> if (isEmpty(s)) return true; <!-- Search through string's' characters one by one until we find a non-whitespace character. --> for (i=0; i < s.length; i++) { <!-- Check that current character isn't' whitespace.--> var currchar = s.charAt(i); if (whitespace.indexOf(currchar) == -1) return false; } <!-- All characters are whitespace. --> return true; } function isradiobuttselected(elem,helperMsg){ <!-- Check to see if atleast one is checkbox checked or not--> for (j=10; j<=11; j++) { if(document.forms[0].elements[j].checked) { break; } else if (j>=11) { alert("Atleast Check on one of the radio buttons"); document.forms[0].elements[j].focus(); return (false); } } return(true); } function ischeckboxselected(elem,helperMsg) { for (j=12; j<=13; j++) { if(document.forms[0].elements[j].checked) { break; } else if (j>=13) { alert("Atleast Check on One of Our Services"); document.forms[0].elements[j].focus(); return (false); } } return(true); } </script> </head> <body> <form onsubmit='return formValidator()' > <br /> First Name: <input type='text' id='firstname' /><br /><br /> Address: <input type='text' id='addr' /><br /><br /> Zip Code: <input type='text' id='zip' /><br /><br /> State: <select id='state'> <option>Please Choose</option> <option>AL</option> <option>KE</option> <option>TX</option> <option>CH</option> </select><br /> Username(6-8 characters): <input type='text' id='username' /><br /><br /> Password(min 4 chars):<input type="password" id='passwd' /> <br/><br /> Confirm Password: <input id="pass2" Type="password" /><br/><br /> Email: <input type='text' id='email' /><br /><br /> Something about Yourself : <textarea name="1" cols="17" rows="4" id="ta"></textarea><br/><br /> Free Membership <input type="radio" id="r1"/> Paid Membership <input type="radio" id="r1"/><br/><br/> Friendship<input type="checkbox" id="box1" /> Networking <input type="checkbox" id="box1" /><br /><br /> <input type='submit' value='Submit' /> </form> </body> </html> I am developing a mobile app. I have a script that will read the contents of a csv into an array. It works great, however I am not sure how to take that array and insert it into a db. The following is the script that reads the csv -- function IO(U, V) { var X = !window.XMLHttpRequest ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest; X.open(V ? "PUT" : "GET", U, false); X.setRequestHeader("Content-Type", "text/html"); X.send(V ? V : ""); return X.responseText; } var mycells = IO('data.csv').split(/\n/g).map(function(a){return a.split(/\t/g)} ) I want to insert the array 'mycells' into the db but do not know what the correct syntax would be. t.executeSql('INSERT INTO mytable (name, phone, street, city, state) VALUES (????????????... Thanks for any helps that is sent my way! I recently coded a page that extracts certain nodes from an external XML file and prints a line of text on the webpage. It is an HTML page that is strictly devoted to this purpose. There is no other information on it. The page is currently stored locally on my computer, and when I open it, the script runs fine and outputs the correct text. However, when I transferred this script over to my web server, and locate it that way, it doesn't run correctly. When I go to the page, it is supposed to display a line of text at the top. It does when I run the file from my local machine, however when I open it from the server, it doesn't display this text. (Same browser, same computer) When I right-click and view the source, all the code is there, and the files are identical. Any idea as to why the script runs correctly only when I open the HTML page locally? I appreciate any help or advice. Thanks! Hi, I am hosting my website in free server (freehostia.com) and i am using joomla1.5 . I want to parse RSS from my other websites. Joomla does it with its modules. But the server do not allow outbound HTTP request, hence i had use rss-to-javascript website to parse RSS feeds. It parses well but there is its advertisement below the feed (which i think is nonsense). The link it provides is in the format of <script src="http://somethin.com/somdfile.php?parse=.."></script> when i put the link in my browser i see following document.write("string of my parsed xml file with advertisement at end"); What i want to do is get the sting of above line and edit it to chop off the end advertisement. if there was any method to load that output sting in any variable, the task would had been completed. If anybody knows how to do it, please help me. I have a google blogger site on which I want to run a PHP script. The problem is that blogger doesn't have a PHP interpreter. So I was thinking, can I run the php file on a remote server that supports php, and load the result in a div in blogger? Thx! Hi, I am creating a HTML page and mailing it to the user(client side). This html page contains a Table and a button. On button click, I would like to create another HTML page based on the detail in the table,dynamically on run time and Open the newly created HTML. I need to use javascript to achieve this functionality. I have no Server-Client Configuration. And I need to run the Javscript only on client side to process the First HTML's table data and Create a new HTML page. The output of the javascript should also be put in a table format in the newly created HTML page. Here is some background information: The details from one server would be put into this first HTML along with a button. This HTML page is then mailed to Client side. The javascript in the HTML page then processes the Table data of first HTML. This can only be run at Client Side,once the user clicks the button and moreover I dont have Server-Client Configuration. I am creating a report and mailing it, For formatting purposes and for creating hyperlink to mailid's I chose HTML, Now I am struck here. Could some one please help me out with this. Thanks for your time. I must make clear that I am not a javascript programmer; I am simply trying to get this script to work on my website. It functions perfectly locally (with all browsers), but after uploading to my website, it shows the controls at the top, but not the content. Below is the code for the FreeMind Flash Browser which can be found he http://freemind.sourceforge.net/wiki.../Flash_browser It requires 2 additional files, flashobject.js and visorFreemind.swf plus the FreeMind file (*.mm) that stores the content. The FreeMind file that has the content displays perfectly on localhost, but not on the website. I have all of these files in the same directory and have double checked everything, but it still doesn't function on my website. I have other flash files and scripts on the same website in other pages that function perfectly. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="freemind flash browser"/> <meta name="keywords" content="freemind,flash"/> <title>MINDMAPS</title> <script type="text/javascript" src="flashobject.js"></script> <style type="text/css"> /* hide from ie on mac \*/ html { height: 100%; overflow: hidden; } #flashcontent { height: 100%; } /* end hide */ body { height: 100%; margin: 0; padding: 0; background-color: #9999ff; } </style> <script language="javascript"> function giveFocus() { document.visorFreeMind.focus(); } </script></head> <body onLoad="giveFocus();"> <div id="flashcontent" onmouseover="giveFocus();"> Flash plugin or Javascript are turned off. Activate both and reload to view the mindmap </div> <script type="text/javascript"> // <![CDATA[ // for allowing using http://.....?mindmap.mm mode function getMap(map){ var result=map; var loc=document.location+''; if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){ result=loc.substring(loc.indexOf("?")+1); } return result; } var fo = new FlashObject("visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#9999ff"); fo.addParam("quality", "high"); fo.addParam("bgcolor", "#a0a0f0"); fo.addVariable("openUrl", "_blank"); fo.addVariable("startCollapsedToLevel","3"); fo.addVariable("maxNodeWidth","200"); // fo.addVariable("mainNodeShape","elipse"); fo.addVariable("justMap","false"); fo.addVariable("initLoadFile",getMap("blues.mm")); fo.addVariable("defaultToolTipWordWrap",200); fo.addVariable("offsetX","left"); fo.addVariable("offsetY","top"); fo.addVariable("buttonsPos","top"); fo.addVariable("min_alpha_buttons",20); fo.addVariable("max_alpha_buttons",100); fo.addVariable("scaleTooltips","false"); fo.write("flashcontent"); // ]]> </script> </body> </html> |