JavaScript - Specify Word Doc Filename In Save Dialogue Box
Hi all,
I have a webform that creates a word document as it's ouput (yes I know it only works on IE). Code: function createWordDoc(){ Doctxt = "some text here" var w=new ActiveXObject("Word.Application"); w.Visible=true; w.Documents.Add(); w.Selection.Font.Name="Times New Roman"; w.Selection.ParagraphFormat.Alignment = 1; w.Selection.TypeText(Doctxt); w.Documents.Save(); } My issue is with saving the file. At the moment, in the above code, it opens the save dialogue box, and populates the filename field with the first line of text in the document. What I want to be able to do is populate the filename field with a variable filename created by the function. Anyone know how to do this? I've tried the snippet below, which works with the dynamic filename, but it autosaves the file to "My Documents" folder without prompting. I need to be able to allow the location to be changed. Code: var FileName = "Myfile.doc" w.ActiveDocument.SaveAs(FileName); Any ideas? Similar TutorialsHello. I am new to the forums (I just started my Javascript journey last week), and was hoping to get help with something. I am currently developing a page which allows access to music on a server. This music is being streamed, but users are also able to download this music (assuming they have the license to do so). All of the music uploaded is of the .mp3 format, however they have no filetype extensions, and were not named using any particular naming convention. Because of this, I was hoping to change the filename (when a downloaded is initiated) to variables I have stored based on the current song. I am currently simply opening a new page, in Chrome is looks like this: Code: chrome.tabs.create({ "url": song.url }) Hit presents the user with a prompt to save the file, however, its default name is a random alphanumeric string with no extension, as per their file name on my server. Is there an easy way to do this without renaming all the music server side? I do have the variables song.title and song.artist setup! All help is appreciated! Edit: Since this page is only for Chrome users, I listed the code I am using. I understand window.open and was originally using this. It functions the same, and if I need to revert back to using is instead, I shall. I need to save an HTML page to Word using JavaScript. Any ideas on that? I have found some script on-line but all of them use the "Save As" procedure which only allows to save in txt and html format. I need it to be in Word. Thanks! Howdy all! Hope Thursday's treatin everybody all right. Way back in the day I did some old school HTML....but after many years not touching a web page I've kind of been thrown straight into the fire with some "wish list" items I'm trying to figure out. I've done plenty of searches and somewhat have an understanding of some of the basics of what I need to do...but I'm not the least bit comfortable with Javascript (I'm just assuming that this the language most applicable to what I'm looking for - please tell me if I'm wrong!) and after the experience of my one day crash course with PHP I knew I needed to turn to some experts. Okay I have a rather large web (about 150 pages) of historical transcriptions created with XHTML (with PHP headers and footers embedded). Generally speaking, I don't much like web pages that have right-click disabled and various other protections in place.....but I'm also the sort to obsessively cite my source material and give proper credits....as a researcher who's hard work has been plagiarized and passed off as the fruits of someone else's labor, I wholly understand why many are inclined to put such walls up. I am aware that there are workarounds to get through almost all such "blocks" - disabling scripts, etc. - and that they serve more as pop-up thought provokers and deterrents to the majority than true security from someone hell-bent on copying the material. Further, I wouldn't want to block an honest researcher from copying/pasting/etc. So this is what I'd wondering... Is it possible to disable right-clicking in a manner that when someone tried, a dialogue/input box with a personal message and request for their name and email address would pop up which (1) would continue to disable right-clicking if "cancel" was chosen rather than the information submitted, (2) would enable right-clicking after they submitted this information - and would keep it enabled until they left the site, and (3) would email me the information. Again, I do know most any solution would be "crackable" and not even show its head to some users...but I think its still worth taking the time to implement...even if it only serves as a thought provoker and appeals to one's conscience. Thanks in advance for any and all help! Brittanie Sorry about the title, I didn't know what else to use to describe my problem. Basically, I'm generating a random word with a function; then I'm trying to pass this word down to another function. The problem is, when I pass the word, it changes each time (due to it being randomly generated originally). I'm only calling the function once (via button click), but I'm also calling the function in my code lower down to retrieve the returned variable; and the function seems to be running again and returning a new word from my array. Here's a snippet of my code: Code: function ranNum(){ var ranNum = Math.round(Math.random()*10); var chosenWord = wordArray[ranNum]; return chosenWord; } function makeBoxes(x){ //remove children when new word is chosen var hM = document.getElementById("hangMan"); while(hM.firstChild){ hM.removeChild(hM.firstChild); } var chosenWord = ranNum(x); var wL = chosenWord.length; //create box for length of letters in word var i = 0; for(i=0;i<wL;i++){ var cBoxes = document.createElement("div"); cBoxes.className = "letterBoxes"; cBoxes.innerHTML = chosenWord.charAt(i); hangMan.appendChild(cBoxes); } return chosenWord; } function checkLetter(y){ var chosenWord = makeBoxes(y); alert(chosenWord); } So I generate a word with one button; now I need to be able to work with said word in my checkLetter() function. The word changes however. Any help would be greatly received. Hi, every time I try and alert: [ { number:0, secondnumber:0 }, { number:2, secondnumber:1 }, { number:1, secondnumber:2 } ] it just shows [object object], [object object], [object object]. Why is this and what can I do to make the record be shown as it is above in an alert? Thanks. I found a nice script online that will count words. Problem is, I need it to also count each DIGIT (0-9) as a seperate word, whether the numbers are seperated by a space or not. I've searched this forum to no avail. Can anyone help me or show me how to do this, here is the original script: Code: <!-- TWO STEPS TO INSTALL WORD COUNT: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- Original: Shawn Seley --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin function CountWords (this_field, show_word_count, show_char_count) { if (show_word_count == null) { show_word_count = true; } if (show_char_count == null) { show_char_count = false; } var char_count = this_field.value.length; var fullStr = this_field.value + " "; var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); var splitString = cleanedStr.split(" "); var word_count = splitString.length -1; if (fullStr.length <2) { word_count = 0; } if (word_count == 1) { wordOrWords = " word"; } else { wordOrWords = " words"; } if (char_count == 1) { charOrChars = " character"; } else { charOrChars = " characters"; } if (show_word_count & show_char_count) { alert ("Word Count:\n" + " " + word_count + wordOrWords + "\n" + " " + char_count + charOrChars); } else { if (show_word_count) { alert ("Word Count: " + word_count + wordOrWords); } else { if (show_char_count) { alert ("Character Count: " + char_count + charOrChars); } } } return word_count; } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <form> <textarea cols=40 rows=5 name=x> </textarea> <br> <input type=button value="Count Words" OnClick ="CountWords(this.form.x, true, true);"> </form> <p><center> <font face="arial, helvetica" size"-2">Free JavaScripts provided<br> by <a href="http://javascriptsource.com">The JavaScript Source</a></font> </center><p> <!-- Script Size: 2.04 KB --> I'm trying to figure out a way to pass the filename before submission... I think I have to make an onChange command on the file field, but not sure how... This is what I have done so far: Code: <script type="text/javascript"> function theimage(){ var imgURL = document.getElementById('myfile').value; ste.execCommand("insertimage", imgURL); } </script> <input name="myfile" type="file" size="30" onchange="theimage();"> I'm trying to pass the value to theimage as sson the filename changes, but I'm doing something wrong... Any help is apreciated... I'm working on an internal website at work and employees have a cookie created when they login to the customer support tool. The filename is cookie:username@domain.com/ and I'd like to use javascript to pull a variable for their username to plug into a URL for a unique link when they're viewing one of our intranet pages. I'm a Javascript newbie so any help is appreciated. @domain.com/ will always be the same but I don't know how to pull the unique username from the filename of the cookie. I don't need to actually read the cookie. Thanks! Hello all, I have in my application input type file for uploading files. How can i do javascript validation to check if filename has special characters in it?? Thanks Hi I am trying to load html stream directly into webbrowser in delphi. The html contains java script. It loads xml and xsl files and display the xml content in the web browser. I got an error, says access denied for the command xmlDoc.load(fname); If I save the html into a file, test.html, and double click it, it is fine, no problem. The code is actually copied from w3schools.com. the html code as followed: <html> <head> <script> function loadXMLDoc(fname){var xmlDoc; if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else { alert('Your browser cannot handle this script'); } xmlDoc.async=false; xmlDoc.load(fname); return(xmlDoc); } function displayResult() { xml=loadXMLDoc("catalog.xml"); xsl=loadXMLDoc("catalog.xsl"); if (window.ActiveXObject) { ex=xml.transformNode(xsl); document.getElementById("example").innerHTML=ex; } } </script> </head> <body id="example" onLoad="displayResult()"> </body> </html> The delphi code is procedure TForm1.WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ; var v: OleVariant; HTMLDocument: IHTMLDocument2; begin memo1.Lines.LoadFromFile('d:\test\htmltxtold.html'); HTMLCode := memo1.Text; WebBrowser1.Navigate('about:blank') ; HTMLDocument := WebBrowser.Document as IHTMLDocument2; v := VarArrayCreate([0, 0], varVariant); v[0] := HTMLCode; HTMLDocument.Write(PSafeArray(TVarData(v).VArray)); HTMLDocument.Close; end; Thanks a lot Hello, Is it possible to store the edited value in the div tag in the original file, such that next time i open the HTML file the new edited value appears. Thanks in advance. Have a Good day. Hey, I'm trying to make a game, I learned how to do so by reading tutorials but the problem is that I do not know how to implement the save/load function into the game, the tutorial surrounding that area was very unclear to me, and here I am... Any tips on how to make this work is greatly appreciated, I wouldn't asked if I hadn't tried my best and every way I could think of. I'm still quite new to coding so... The first piece of code is the game, the second one is what I'm trying to make the game work with. I tried for a while and got the game to reset back to values, but only the values I set in the code so it never actually worked. The tutorial doesn't give any live examples and I really am... not that bright when it comes to coding Sorry and thanks, all inputs are appreciated. I read tutorial from links below, Javascript String Compression | Almost Idle Tutorial for save code Incremental Lesson 9 - For Loops | Almost Idle Tutorial for the game code Code: /*Pleae refer to Lesson 9.txt for a full description on this lesson*/ //The timer to run code every second var Timer = window.setInterval(function(){Tick()}, 1000); var buildings = []; //The object declaration for game saves function GameSave() { this.money = 0; this.buildings = []; for (var i = 0;i < buildings.length;i++) { this.buildings[i] = 0; } } //The object declaration for buildings function Building() { this.Name = "Lemonade Stand"; this.Cost = 10; this.PerSec = 1; } //The function to initialise all buildings function InitBuildings() { LoadBuilding("Lemonade Stand",10,1); } //The function to automatically load a building into the buildings array function LoadBuilding(name,cost,persec) { var cur = buildings.length; buildings[cur] = new Building(); buildings[cur].Name = name; buildings[cur].Cost = cost; buildings[cur].PerSec = persec; } //The function used to gather money function GatherMoney() { game.money++; //++ tells javascript to add 1 to the variable //Display the player's current money document.getElementById("money").innerHTML = game.money; } //The function that gets run every second function Tick() { for (var i = 0;i < buildings.length;i++) { game.money += game.buildings[i] * buildings[i].PerSec; } document.getElementById("money").innerHTML = game.money; } //The function to buy a lemonade stand function Build(id) { if (game.money >= buildings[id].Cost) { //Check if the player has enough money, then subtract it and add a new building if they do game.money -= buildings[id].Cost; game.buildings[id] = game.buildings[id] + 1; document.getElementById("money").innerHTML = game.money; document.getElementById("Building1Qty").innerHTML = game.buildings[id]; } } //Run this code once the page has loaded fully window.onload = function() { InitBuildings(); window.game = new GameSave(); }; Code: /*Pleae refer to Compression.txt for a full description on this lesson*/ function NewGame() { this.name = "Our Game"; this.description = "Our Game's Description"; this.numbers = []; for (var i=0;i<10;i++) { this.numbers[i] = i; } } var Game = new NewGame(); window.onload = function() { var SaveGame = JSON.stringify(Game); SaveGame = encode_utf8(SaveGame); SaveGame = lzw_encode(SaveGame); window.localStorage['SaveName'] = SaveGame; SaveGame = window.localStorage['SaveName']; SaveGame = lzw_decode(SaveGame); SaveGame = decode_utf8(SaveGame); window.GameTwo = JSON.parse(SaveGame); document.getElementById("name").innerHTML = "Name: " + GameTwo.name; document.getElementById("desc").innerHTML = "Description: " + GameTwo.description; var numbers = ""; for (var i=0;i<10;i++) { if (numbers.length == 0) {numbers = i;} else {numbers += ", " + i;} } document.getElementById("numbers").innerHTML = "Numbers: " + numbers; } // LZW-compress a string function lzw_encode(s) { var dict = {}; var data = (s + "").split(""); var out = []; var currChar; var phrase = data[0]; var code = 256; for (var i=1; i<data.length; i++) { currChar=data[i]; if (dict['_' + phrase + currChar] != null) { phrase += currChar; } else { out.push(phrase.length > 1 ? dict['_'+phrase] : phrase.charCodeAt(0)); dict['_' + phrase + currChar] = code; code++; phrase=currChar; } } out.push(phrase.length > 1 ? dict['_'+phrase] : phrase.charCodeAt(0)); for (var i=0; i<out.length; i++) { out[i] = String.fromCharCode(out[i]); } return out.join(""); } // Decompress an LZW-encoded string function lzw_decode(s) { var dict = {}; var data = (s + "").split(""); var currChar = data[0]; var oldPhrase = currChar; var out = [currChar]; var code = 256; var phrase; for (var i=1; i<data.length; i++) { var currCode = data[i].charCodeAt(0); if (currCode < 256) { phrase = data[i]; } else { phrase = dict['_'+currCode] ? dict['_'+currCode] : (oldPhrase + currChar); } out.push(phrase); currChar = phrase.charAt(0); dict['_'+code] = oldPhrase + currChar; code++; oldPhrase = phrase; } return out.join(""); } function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } Reply With Quote 01-16-2015, 05:52 PM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts the problem is that I do not know how to implement the save/load function into the game save it where? that particular question is important as JavaScript has only limited places where it can save something at all. 1) save it on the server => call a server script with the appropriate data (e.g. via AJAX) 2) cookies, very limited storage space, only works on the same browser 3) WebStorage, more space than cookies, but still only the same browser 4) IndexedDB (same as above) Hi.. I have checkbox and I need to get his value. I create function for checkbox if checkbox is clicked it is true then the checkbox value is H else W. Code: function chk(){ if(document.getElementById('H').checked==true){ var H = document.getElementById('H'). value = H; } else if(document.getElementById('H').checked==false){ var H = document.getElementById('H'). value = W; } } and I have function for save : Code: function ApproveLeaveOP(){ var H = document.getElementById('H').value; document.sampleform.action="AddLeave.php?H="+H; document.sampleform.submit(); } <input type="checkbox" name="H" id="H" value="" onclick="chk()"> I don't know how can I add value to the checkbox if I click the value will be H if not the value is W. I am new in using checkbox. Thank you so much.. Hello all, i am a newbie here. I am starting to programme with javascript. I am designing a website. in This website there is an input with type = text and beside this input, there is another input with type = submit. If i open this website: The default value on the search text is "Enter a text", and if I click submit button, this button can recognize the value of the search text which is "Enter a text". <input id="searchText" type="submit" value="Enter a text"/> <input id="searchSubmit" type="submit" value="Submit"/> And then i modified a little bit. I have this javascript: var searchInput = $('#searchText'); searchInput.focus( function() { searchInput.attr('value', ''); }); The goal is, when I click on the search text, the default text is gone. And it worked. But if i write a new text on the search text, the submit button still recognized the value of search text as empty string. Can anyone please help me?? Thank you Hi all, I found this script online that lets users on an iPhone drag boxes around the screen. The problem is that when you reload the page, the boxes are in different positions than what they were before the reload. Like, you would drag the boxes around and then reload the page, but the boxes would be in the default locations. I want the boxes to stay in the same spot that they were the previous time they moved them. Does that make sense? Anyways, here's the example I found online: http://www.manifestinteractive.com/iphone/touch/ Only works on iPad/iPhone/iPod Touch. It uses jQuery too so if you know of any way to do this, that would be excellent. Thanks. I have a long survey form and once its submitted it gets recorded into a database. I would love to be able to save a PDF version of the HTML form with all their radio buttons and textfields filled out at the same time its submitted. It would need a unique name that matches their record in the database (maybe it pulls the data that was entered into one of the form fields for the name). Whether it gets uploaded to an ftp or just emailed to a mailbox doesn't really matter. The purpose of this is to basically have a visual interpretation of the data by a single user. Is something like this even possible? Hey guys, I think this is some pretty basic JavaScript but I'm not too familiar with the language and would really appreciate some help here. I have an image switcher script setup. Its very basic and changes the image displayed on click of a link. Here is what I currently have: Javascript: Code: <script type="text/javascript"> function changeIt(imageName,objName) { var obj = document.getElementById(objName); var imgTag = "<img src='"+imageName+"' border='0' />"; obj.innerHTML = imgTag; return; } </script> HTML: Code: <div id="image1"> <img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/49057_100001550995222_9679_q.jpg" border="0" alt="one" /> </div> <br> <a id="one" href="#" onclick="changeIt('http://profile.ak.fbcdn.net/hprofile-ak-snc4/49057_100001550995222_9679_q.jpg','image1');">one</a> <a id="two" href="#" onclick="changeIt('http://profile.ak.fbcdn.net/hprofile-ak-snc4/174411_100002333675750_7453320_q.jpg','image1');">two</a> <a id="three" href="#" onclick="changeIt('http://profile.ak.fbcdn.net/hprofile-ak-snc4/41512_100000999943382_7276_q.jpg','image1');">three</a> <a id="four" href="#" onclick="changeIt('http://profile.ak.fbcdn.net/hprofile-ak-snc4/41477_100001406980454_629_q.jpg','image1');">four</a> <a id="five" href="#" onclick="changeIt('http://www.dead-paramour.org/fans/fanMCR4.jpg','image1');">five</a> Its very basic but does what I want. What I'm attempting to do is store the image selected as a cookie so that when users refresh/navigate to other pages the image stays to the one they selected. Is anyone able to help me out with this? Any help is greatly appreciated. Thanks, Chris I am trying to do this and have some code im working with. I can load the file through a browse button then save it using the existing code. However, I want instead of the browse option to just preload the file into the textarea and then be able to save it. Code: <script language="javascript"> <!--// var oFileSystem; oFileSystem = new ActiveXObject("Scripting.FileSystemObject"); function ShowFile(sFilePath){ frmEditHTML.tarHTMLText.value = oFileSystem.OpenTextFile(sFilePath).ReadAll(); } function SaveAfterEditing(){ var oFile; oFile = oFileSystem.CreateTextFile(frmEditHTML.filPath.value,1); oFile.WriteLine(frmEditHTML.tarHTMLText.value); oFile.Close(); } </script> Code: <form name="frmEditHTML"> <input type="file" name="filPath" onchange="ShowFile(this.value)"> <br><textarea name="tarHTMLText" cols=60 rows=20></textarea><br> <input type="button" value="Save" name="cmdSave" onclick="SaveAfterEditing()"> </form> This is code use to save XML file using Javascipt but it can't not save full Processing Instruction, example we have PI is <?xml version="1.0" encoding="utf8"> when run the code then PI is saved with <?xml version="1.0"> and sometime it doesn't word. Please help me fix, thanks PHP Code: function SaveXML(xmlDoc,filename) { var outputXML = xmlDoc.xml; var mfObj = new ActiveXObject("Scripting.FileSystemObject"); var absPath = getPath(); var file = mfObj.CreateTextFile(absPath + filename, true); file.Write(outputXML); file.Close(); } function getPath() { var path = document.location; var str = new String(path); var end = str.lastIndexOf("/"); var absolutePath = str.substring(8, end) + "/"; absolutePath = absolutePath.replace(/%20/g, " "); return absolutePath; } |