JavaScript - How To Generate 13 Digit Numbers To Text File
Can someone please help me generate a series of 13 digit numbers and output them to a text file. I'm really desperate here.
Thanks guys. Similar TutorialsHi, I am trying to modify this poetry generator script: Poem Generator .js-file: PHP Code: // Poem Generator JavaScript // Keith Enevoldsen, thinkzone.wlonk.com random_count=0; nsentences=0; nwords1=0; nwords2=0; nwords3=0; nwords4=0; nwords5=0; nwords6=0; nwords7=0; nwords8=0; nwords9=0; function init(form) { form.Samples.selectedIndex=1; generate_input(form, form.Samples.options[form.Samples.selectedIndex].text); make_poem(form); } function generate_input(form, sample_name) { form.title1.value = "Concrete Nouns"; form.title2.value = "Abstract Nouns"; form.title3.value = "Transitive Verbs"; form.title4.value = "Intransitive Verbs"; form.title5.value = "Adjectives"; form.title6.value = "Adverbs"; form.title7.value = ""; form.title8.value = ""; form.title9.value = "Interjections"; form.sentences.value = "The 5 1 6 3s the 1." +"\n5, 5 1s 6 3 a 5, 5 1." +"\n2 is a 5 1." +"\n9, 2!" +"\n1s 4!" +"\nThe 1 4s like a 5 1." +"\n1s 4 like 5 1s." +"\nWhy does the 1 4?" +"\n4 6 like a 5 1." +"\n2, 2, and 2." +"\nWhere is the 5 1?" +"\nAll 1s 3 5, 5 1s." +"\nNever 3 a 1." ; if (sample_name == "Sea") { form.list1.value = "sea\nship\nsail\nwind\nbreeze\nwave\ncloud\nmast\ncaptain\nsailor\nshark\nwhale\ntuna\nseashell\npirate\nlad\ngirl\ngull\nreef\nshore\nmainland\nmoon\nsun"; form.list2.value = "adventure\ncourage\nendurance\ndesolation\ndeath\nlife\nlove\nfaith"; form.list3.value = "command\nview\nlead\npull\nlove\ndesire\nfight"; form.list4.value = "travel\nsail\nwave\ngrow\nrise\nfall\nendure\ndie"; form.list5.value = "big\nsmall\nold\ncold\nwarm\nsunny\nrainy\nmisty\nclear\nstormy\nrough\nlively\ndead"; form.list6.value = "swiftly\ncalmly\nquietly\nroughly"; form.list7.value = ""; form.list8.value = ""; form.list9.value = "o\noh\nooh\nah\nlord\ngod\nwow\ngolly gosh"; } else if (sample_name == "City") { form.list1.value = "street\nsidewalk\ncorner\ndoor\nwindow\nhood\nslum\nskyscraper\ncar\ntruck\nguy\ngirl\njob\nflower\nlight\ncigarette\nrain\njackhammer\ndriver\nworker"; form.list2.value = "action\nwork\nnoise\ndesolation\ndeath\nlife\nlove\nfaith\nanger\nexhaustion"; form.list3.value = "get\ngrab\nshove\nlove\ndesire\nbuy\nsell\nfight\nhustle\ndrive"; form.list4.value = "talk\ngab\nwalk\nrun\nstop\neat\ngrow\nshrink\nshop\nwork"; form.list5.value = "big\nsmall\nold\nfast\ncold\nhot\ndark\ndusty\ngrimy\ndry\nrainy\nmisty\nnoisy\nfaceless\ndead"; form.list6.value = "quickly\nloudly\ncalmly\nquietly\nroughly"; form.list7.value = ""; form.list8.value = ""; form.list9.value = "o\noh\nooh\nah\nlord\ngod\ndamn"; } else { clear_all(form); } form.outtext.value = ""; count_all_lines(form); } function clear_all(form) { form.Samples.value = "-"; form.title1.value = ""; form.title2.value = ""; form.title3.value = ""; form.title4.value = ""; form.title5.value = ""; form.title6.value = ""; form.list1.value = ""; form.list2.value = ""; form.list3.value = ""; form.list4.value = ""; form.list5.value = ""; form.list6.value = ""; form.list7.value = ""; form.list8.value = ""; form.list9.value = ""; form.sentences.value = ""; form.outtext.value = ""; count_all_lines(form); } function count_all_lines(form) { nwords1 = count_lines(form.list1); nwords2 = count_lines(form.list2); nwords3 = count_lines(form.list3); nwords4 = count_lines(form.list4); nwords5 = count_lines(form.list5); nwords6 = count_lines(form.list6); nwords7 = count_lines(form.list7); nwords8 = count_lines(form.list8); nwords9 = count_lines(form.list9); nsentences = count_lines(form.sentences); } function random(maxnum) { r = Math.floor(Math.random() * maxnum) + 1; if (r > maxnum) r = maxnum; return r; } function count_lines(txt) { str = txt.value; len = str.length; nword = 1; for (i = 0; i < len; i++) { if (str.charAt(i) == "\n") { nword++; } } if (str.charAt(len-1) == "\n") nword--; return nword; } function get_line(str, lnum) { len = str.length; iline = 1; ichar = 0; jchar = -1; for (i = 0; i < len; i++) { if (str.charAt(i) == "\n") { iline++; if (iline == lnum) { ichar = i + 1; } else if (iline == (lnum + 1)) { jchar = i - 1; if (str.charAt(jchar) == "\r") { jchar--; } break; } } } if (jchar < 0) jchar = len - 1; // Note: Use loop because substr() doesn't work consistently on old browsers s = ""; for (i = ichar; i <= jchar; i++) { s = s + str.charAt(i); } return s; } function initial_cap(str) { // Note: Use loop because substr() doesn't work consistently on old browsers len = str.length; s = ""; for (i = 0; i <= len; i++) { if (i == 0) { s = s + str.charAt(i).toUpperCase(); } else { s = s + str.charAt(i); } } return s; } function make_poem(form) { form.outtext.value = ""; count_all_lines(form); nlines = random(4) + 1; for (ilin = 1; ilin <= nlines; ilin++) { make_poem_line(form) } } function make_poem_line(form) { pattern = get_line(form.sentences.value, random(nsentences)); lenpat = pattern.length; for (ichr = 0; ichr < lenpat; ichr++) { chr = pattern.charAt(ichr); // If the pattern contains a digit n, then pick a random word from list n if ((chr >= '1') && (chr <= '9')) { if (chr == '1') { wrd = get_line(form.list1.value, random(nwords1)); } else if (chr == '2') { wrd = get_line(form.list2.value, random(nwords2)); } else if (chr == '3') { wrd = get_line(form.list3.value, random(nwords3)); } else if (chr == '4') { wrd = get_line(form.list4.value, random(nwords4)); } else if (chr == '5') { wrd = get_line(form.list5.value, random(nwords5)); } else if (chr == '6') { wrd = get_line(form.list6.value, random(nwords6)); } else if (chr == '7') { wrd = get_line(form.list7.value, random(nwords7)); } else if (chr == '8') { wrd = get_line(form.list8.value, random(nwords8)); } else if (chr == '9') { wrd = get_line(form.list9.value, random(nwords9)); } else { wrd = ''; } // Capitalize first letter of sentence if (ichr == 0) { wrd = initial_cap(wrd); } form.outtext.value = form.outtext.value + wrd; } else { form.outtext.value = form.outtext.value + chr; } } form.outtext.value = form.outtext.value + "\n"; } And the .html: PHP 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> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Poem Generator</title> <meta name="Description" content="Poem Generator"> <meta name="Keywords" content="Poem Generator"> <meta name="robots" content="all"> <link rel="icon" href="http://thinkzone.wlonk.com/thinkzone_icon.png"> <link rel="stylesheet" href="Poem%20Generator_files/style.css" type="text/css"> <script type="text/javascript" src="Poem%20Generator_files/PoemGen.js"></script> </head> <body onload="init(document.form)" style="background-color: #99CC99;"> <div class="bodydiv" style="background-color: #99CC99;"> <div align="center"> <a href="http://thinkzone.wlonk.com/index.htm"><img alt="thinkzone.wlonk.com" src="Poem%20Generator_files/thinkzone_wlonk_trans.png"></a> <h2>Poem Generator</h2> <p>This makes random poems. First, it randomly selects sentence patterns. Then, wherever the pattern has a number, it randomly selects a word from one of the numbered word lists. You can either choose one of the sample sets of words and sentence patterns, or you can enter your own words and sentence patterns.</p> <form name="form" id="form" action=""> <input value="Make Poem" onclick="make_poem(this.form)" type="button"><br> <textarea cols="70" rows="6" name="outtext">Grow swiftly like a clear wind. The reef falls like a rough sun. </textarea><br> <br> <b>Word Lists</b><br> Samples: <select name="Samples" onchange="generate_input(this.form, this.options[this.selectedIndex].text)"> <option>-</option> <option selected="selected">Sea</option> <option>City</option> </select> <input value="Clear Lists" onclick="clear_all(this.form)" type="button"><br> <table> <tbody> <tr> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> <th>6</th> <th>7</th> <th>8</th> <th>9</th> </tr> <tr> <td><textarea cols="12" rows="2" name="title1">Concrete Nouns</textarea></td> <td><textarea cols="12" rows="2" name="title2">Abstract Nouns</textarea></td> <td><textarea cols="12" rows="2" name="title3">Transitive Verbs</textarea></td> <td><textarea cols="12" rows="2" name="title4">Intransitive Verbs</textarea></td> <td><textarea cols="12" rows="2" name="title5">Adjectives</textarea></td> <td><textarea cols="12" rows="2" name="title6">Adverbs</textarea></td> <td><textarea cols="12" rows="2" name="title7"></textarea></td> <td><textarea cols="12" rows="2" name="title8"></textarea></td> <td><textarea cols="12" rows="2" name="title9">Interjections</textarea></td> </tr> <tr> <td><textarea cols="12" rows="10" name="list1">sea ship sail wind breeze wave cloud mast captain sailor shark whale tuna seashell pirate lad girl gull reef shore mainland moon sun</textarea></td> <td><textarea cols="12" rows="10" name="list2">adventure courage endurance desolation death life love faith</textarea></td> <td><textarea cols="12" rows="10" name="list3">command view lead pull love desire fight</textarea></td> <td><textarea cols="12" rows="10" name="list4">travel sail wave grow rise fall endure die</textarea></td> <td><textarea cols="12" rows="10" name="list5">big small old cold warm sunny rainy misty clear stormy rough lively dead</textarea></td> <td><textarea cols="12" rows="10" name="list6">swiftly calmly quietly roughly</textarea></td> <td><textarea cols="12" rows="10" name="list7"></textarea></td> <td><textarea cols="12" rows="10" name="list8"></textarea></td> <td><textarea cols="12" rows="10" name="list9">o oh ooh ah lord god wow golly gosh</textarea></td> </tr> </tbody> </table> <br> <b>Sentence Patterns</b><br> <textarea cols="40" rows="10" name="sentences">The 5 1 6 3s the 1. 5, 5 1s 6 3 a 5, 5 1. 2 is a 5 1. 9, 2! 1s 4! The 1 4s like a 5 1. 1s 4 like 5 1s. Why does the 1 4? 4 6 like a 5 1. 2, 2, and 2. Where is the 5 1? All 1s 3 5, 5 1s. Never 3 a 1.</textarea></form> <p>You can see the JavaScript source code in PoemGen.htm and PoemGen.js.</p> </div> <hr> <div align="center"> <a href="http://thinkzone.wlonk.com/index.htm">Keith Enevoldsen's Think Zone</a> </div> </div> </body></html> What I want to do is add more word lists. This of course is easy in principle - I can just continue the lists like: form.title9.value = ""; form.title10.value = ""; form.title11.value = ""; - and so on. The problem is that, in the "sentence patterns", I cannot use numbers with two digits to refer to the word lists. Then it thinks I mean 1+0 and 1+1 instead of 10 and 11. How can I allow this? I have heard about using regular expressions to "capture the number by its word boundary" - is this a good solution? If yes, can someone please explain to me how to do it? (I have tried special characters like @,#,$ and more as well as Russian and Greek letters. This makes the script unable to generate poems.) Thank you. Reply With Quote 12-28-2014, 08:31 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Convert the string values which are concatenated by + (e.g. "2" + "5" = 25) into numbers (e.g. 2+5 = 7) by using the Number() method, or another way is to multiply the value by 1. But you are using string values if (chr == '1') { quite unnecessarily. Remove the quote marks to make them into numbers. "1" is a string value. 1 is a number Obviously chr = pattern.charAt(ichr); only captures a single numeric chararcter. You can extract two-digit numbers from a string just by removing all non-digits var x = str.replace(/[^0-9]/g,""); // strip all characters but digits That of course assumes that there is only one number in the string. Haikus are easy But sometimes they don't make sense. Refrigerator. Dear friends, I was looking for some help on getting all the ten digits mobile numbers in the current webpage and assign an onclick event to it just by a click of a button. Likewise, Suppose there are mobile numbers Code: <p>9876543210 Blah....Blah...Any other content.9654321000</p> <input type="button" value="Get 10 digit mobile numbers" onclick="getnumbers();" /> in the current webpage. and the user clicks on a button. Then all the ten digit mobile numbers(in this case two numbers 9876543210 and 9654321000) gets the html as Code: <p><span onclick="openpopup('9876543210')">9876543210</span> Blah....Blah...Any other content.<span onclick="openpopup('9654321000')">9654321000</span></p> I am a PHP guy and probably suck at JS. Tried experimenting with the following code but didn't got it to work. Code: var html = document.getElementsByTagName('body')[0].innerHTML; and match = new RegExp("/\d{10}/"); replaceWith = "<span style='text-decoration:underline;' onclick=\"openpopup('--NUMBER--')\" >--NUMBER--</span>", replaced = html.replace(pattern,replaceWith); Please get me out of this glitch as it is getting harder for me to do it. Hi, I want to when I open a web page , my program detect all the "digit numbers" and display all of them for me. I don't know exactly what do I do? Thanks. Regards. i have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads. var random = Math.floor(Math.random()*40 + 1) //sets variables for random numbers to generate var random2 = Math.floor(Math.random()*40 + 1) var random3 = Math.floor(Math.random()*40 + 1) var random4 = Math.floor(Math.random()*40 + 1) var random5 = Math.floor(Math.random()*40 + 1) var random6 = Math.floor(Math.random()*40 + 1) //create table function makeTable(lotto) document.getElementById("tableSpan").innerHTML = '<table border="1" id="lotto">'; var caption=document.getElementById('lotto').createCaption(); caption.innerHTML="JavaScript Random Numbers"; var x=document.getElementById('lotto').insertRow(0); var cell1=x.insertCell(0); var cell2=x.insertCell(1); var cell3=x.insertCell(2); var cell4=x.insertCell(3); var cell5=x.insertCell(4); var cell6=x.insertCell(5); cell1.innerHTML='<td class = "normal">'+ random +'</td>'; cell2.innerHTML='<td class = "normal">'+ random2 +'</td>'; cell3.innerHTML='<td class = "normal">'+ random3 +'</td>'; cell4.innerHTML='<td class = "normal">'+ random4 +'</td>'; cell5.innerHTML='<td class = "normal">'+ random5 +'</td>'; cell6.innerHTML='<td class = "red">'+ random6 +'</td>'; } heres the HTML file: <body onload="makeTable('lotto');"> <div id="container"> <div id="header"> <h1>Welcome</h1> </div> <div id="content"> <span id="tableSpan"></span> <input type="button" value="Re-generate Numbers" onclick="makeTable('lotto');" /> </div> { Hey guys I'm trying to figure out the best/easiest/fastest way to accomplish this task: I have a csv file I need to generate an HTML item description based on the infomation in this csv Here is an example: ITEM NAME, ITEM TITLE, MANUFACTURE, CONDITION, LAST PHOTO LINK, I would then need the script to generate the HTML markup AND I will also need the script to determine if the last photo in the list is photo "c" and then create the links for photos a-c ie: <b>ITEM NAME<b><br> <i>ITEM TITLE</i><br> <img src="photoa.jpg"><img src="photob.jpg"><img src="photoc"><br><br> ect.... I'm sure there is a good way to do this I'm just not sure which language will be the easiest to do it in. If there is a way to use java I am most familiar with java. I would also like the script to export the data in a csv file as well if possible. Thanks for any advice guys! Please if you have any reference links post them! Hi I am trying to use stoutlabs content slider on my website. I have a dummy set up here www.mattbbell.com Instead of the numbered navigation i want to have text like home, bio, contact etc The demo can be download here http://stoutlabs.com/demos/class_sli..._slider_v2.zip with all files necessary to make the dummy website you see there... From what i can tell I have to edit the sl_slider_new.js file and make it call a list of divs that i name home, bio, contact I think this is the section i need to edit but i don't know much about javascript.... Code: // -- Number nav setup if(self.options.numNavActive == true){ //create numbered navigation boxes, and insert into the 'num_nav' ul) var numItem = new Element('li', {id: 'num'+i}); var numLink = new Element('a', { 'class': 'numbtn', 'html': (i+1) }); numItem.adopt(numLink); self.options.numNavHolder.adopt(numItem); self.numNav.push(numLink); numLink.set('morph', {duration: 100, transition: Fx.Transitions.linear, link: 'ignore'}); numLink.addEvents({ 'click' : function(){ self.numPress(i); }, 'mouseenter' : function() { this.setStyle('cursor', 'pointer'); } }); //set initial number to active state if(i == self.options.itemNum){ var initNum = self.numNav[i]; initNum.addClass('active'); } } //end if num nav 'active' }); }, thanks! hi please help, i want to select numbers from a list box and add it to a text box with comma separated. my java script code does not work into browser but work fine into eclipse jsp view. Code: function passingNumbersToTextArea(numToCall,allNum) { var numFromList=document.getElementById(allNum); var numToTextArea=document.getElementById(numToCall); if(numToTextArea.value.search(numFromList.value)!=-1)//if duplicate Number is exist { alert("Duplicate Number Can not be added :"); return false; } else { if(numToTextArea.value.length!=0) { // If textarea has value than it added another value with comma seperated numToTextArea.value=numToTextArea.value+','+numFromList.value; return false; } else { numToTextArea.value=numFromList.value; return false; } } } jsp code <h:inputTextarea cols="10" rows="4" id="numberToCall" required="true" value="#{conferenceCall.numberToCall}" styleClass="form_input_box" /> <h:selectOneListbox styleClass="form_selectmenu" id="allNumbers" size="5" onclick="passingNumbersToTextArea('numberToCall','allNumbers');"> <f:selectItem itemValue="9971701077" itemLabel="Sharad : 9971701077"/> <f:selectItem itemValue="9990102381" itemLabel="Saurabh : 9990102381"/> </h:selectOneListbox> javascript debugger shows error Error ``numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0. Exception ``TypeError: numToTextArea is null'' thrown from function passingNumbersToTextArea(allNum=string:"allNumbers", numToCall=string:"numberToCall") in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 21. [e] message = [string] "numToTextArea is null" Exception ``TypeError: numToTextArea is null'' thrown from function onclick(event=MouseEvent:{0}) in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 1. [e] message = [string] "numToTextArea is null" Error ``TypeError: numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0. Thanks & Regards: Saurabh I have a database script that returns dates in the following format: yyyy-mm-dd I have been using the following code to change this format to dd-mm-yyyy: Code: <script type="text/javascript"> var myString = "[[date]]"; var mySplitResult = myString.split("-");document.write(mySplitResult[2] + "/" + mySplitResult[1] + "/" + mySplitResult[0] ); </script> However, I now want to display the date in text format, e.g. 01-08-2009 would be displayed as 01 August 2009. Could anyone please let me know how I change the script to show this format? Many thanks in advance, Neil I'm creating a page that calculates a number depending on what value is inputted into a text field. I need to create some javascript that updates this new calculated value and outputs it next to the input field. Anytime the user changes the number, it recalculates the value. My calculation is currently being produced by PHP, however if I need to, I can create javascript as well to recalculate these numbers. My formulas for all 4 calculations are as follows: First: Inputted Value * 10 Second: Inputted Value * 20 Third: Inputted Value / 2 Fourth: Inputted Value * 2 Here is my code I'm working with: PHP Code: <?php session_start(); $username = $_SESSION['username']; include_once('inc/connect.php'); $credquery = mysql_query("SELECT * FROM userstats WHERE username='$username'"); $row = mysql_fetch_assoc($credquery); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $sitetobanner = $_POST['sitetobanner']; $sitetotext = $_POST['sitetotext']; $bannertotext = $_POST['bannertotext']; $texttobanner = $_POST['texttobanner']; if (isset($sitetobanner)){ $bannerimp = round($_POST['bannerimp']); if ($bannerimp > 1){ $s = "s"; } if ($bannerimp <= $credits){ $newcredits = $credits - $bannerimp; $newbannercredits = $bannerimp * 10; $totalbannercredits = $bannercredits + $newbannercredits; $updatebanner = mysql_query("UPDATE userstats SET credits='$newcredits', bannercredits='$totalbannercredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedbanner = "You converted ".$bannerimp." credit".$s." into ".$newbannercredits." banner impressions"; } else{ if ($credits>1){ $mycredits = $credits - 1;} $errorbanner = number_format($mycredits, 0, '.', ''); } } if (isset($sitetotext)){ $textimp = round($_POST['textimp']); if ($textimp > 1){ $s = "s"; } if ($textimp <= $credits){ $newcredits = $credits - $textimp; $newtextcredits = $textimp * 20; $totaltextcredits = $textcredits + $newtextcredits; $updatebanner = mysql_query("UPDATE userstats SET credits='$newcredits', textcredits='$totaltextcredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedtext = "You converted ".$textimp." credit".$s." into ".$newtextcredits." text ad impressions"; } else{ if ($credits>1){ $mycredits = $credits - 1;} $errortext = number_format($mycredits, 0, '.', ''); } } if (isset($texttobanner)){ $texttobannerimp = round($_POST['texttobannerimp']); if ($texttobannerimp > 1){ $s = "s"; } if ($texttobannerimp <= $textcredits){ if ($texttobannerimp>=2&&$texttobannerimp>""){ $newcredits = $textcredits - $texttobannerimp; $newbannercredits = $texttobannerimp / 2; $totalbannercredits = $bannercredits + $newbannercredits; $updatebanner = mysql_query("UPDATE userstats SET textcredits='$newcredits', bannercredits='$totalbannercredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedtextimp = "You converted ".$texttobannerimp." text ad impression".$s." into ".$newbannercredits." banner impressions"; } else{ $convertedtextimp = "You Hag"; } } else{ if ($textcredits>1){ $mycredits = $textcredits - 1;} $errortextimp = number_format($mycredits, 0, '.', ''); } } if (isset($bannertotext)){ $bannertotextimp = round($_POST['bannertotextimp']); if ($bannertotextimp > 1){ $s = "s"; } if ($bannertotextimp <= $bannercredits){ $newcredits = $bannercredits - $bannertotextimp; $newtextcredits = $bannertotextimp * 2; $totaltextcredits = $textcredits + $newtextcredits; $updatebanner = mysql_query("UPDATE userstats SET bannercredits='$newcredits', textcredits='$totaltextcredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedbannerimp = "You converted ".$bannertotextimp." banner impression".$s." into ".$newtextcredits." text impressions"; } else{ if ($bannercredits>1){ $mycredits = $bannercredits - 1;} $errorbannerimp = number_format($mycredits, 0, '.', ''); } } ?> <html> <head> <title>Convert Credits</title> <script type="text/javascript" language="javascript"> function inputLimiter(e,allow) { var AllowableCharacters = ''; if (allow == 'NumbersOnly'){AllowableCharacters='0123456789.';} var k; k=document.all?parseInt(e.keyCode): parseInt(e.which); if (k!=13 && k!=8 && k!=0){ if ((e.ctrlKey==false) && (e.altKey==false)) { return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); } else { return true; } } else { return true; } } </script> </head> <body> <h1>Convert Credits</h1><br /> Credits: <?php echo $credits; ?><br /> Banner Impressions: <?php echo $bannercredits; ?><br /> Text Ad Impressions: <?php echo $textcredits; ?><br /> <form action="convert.php" method="POST"> <h3>Credits To Banner Impressions</h3> Convert <input type="text" name="bannerimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errorbanner; ?>" onChange=""> credits into BLANK Banner Impressions! <input type="submit" name="sitetobanner" value="Convert"><br /> <?php echo $convertedbanner; ?> </form> <form action="convert.php" method="POST"> <h3>Credits To Text Ad Impressions</h3> Convert <input type="text" name="textimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errortext; ?>"> credits into BLANK Text Ad Impressions! <input type="submit" name="sitetotext" value="Convert"><br /> <?php echo $convertedtext; ?> </form> <form action="convert.php" method="POST"> <h3>Text Ad To Banner Impressions</h3> Convert <input type="text" name="texttobannerimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errortextimp; ?>"> Text Ad Impressions into BLANK Banner Impressions! <input type="submit" name="texttobanner" value="Convert"><br /> <?php echo $convertedtextimp; ?> </form> <form action="convert.php" method="POST"> <h3>Banner To Text Ad Impressions</h3> Convert <input type="text" name="bannertotextimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errorbannerimp; ?>"> Banner Impressions into BLANK Text Ad Impressions! <input type="submit" name="bannertotext" value="Convert"><br /> <?php echo $convertedbannerimp; ?> </form> </body> </html> Hi all, I'm self learning JavaScript and this got me stumpped. I've wrote a very similar function that works perfect but no matter what i do here, the result is always the same. I can't seem to enter a 2 digit number in the second box for weight and therfore won't work. It seems to work fine for up to 9 lbs though. can anyone shed light to this? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script> //this array contains strings that can be broken down //into Shipping Zone, Shipping Range, Shipping Charges //This array is for origin zip 532xx. Weight max is 10lbs var PriorityMailArray = new Array("1 01 04.90", "2 01 04.90", "3 01 04.95", "4 01 05.05", "5 01 05.15", "6 01 05.25", "7 01 05.35", "8 01 05.55", "1 02 05.00", "2 02 05.00", "3 02 05.35", "4 02 05.95", "5 02 07.50", "6 02 08.10", "7 02 08.60", "8 02 09.55", "1 03 05.70", "2 03 05.70", "3 03 06.55", "4 03 07.50", "5 03 09.00", "6 03 09.95", "7 03 10.70", "8 03 12.70", "1 04 06.45", "2 04 06.45", "3 04 07.55", "4 04 08.60", "5 04 11.90", "6 04 13.00", "7 04 13.80", "8 04 15.30", "1 05 07.65", "2 05 07.65", "3 05 08.75", "4 05 09.85", "5 05 13.50", "6 05 14.85", "7 05 15.85", "8 05 17.65", "1 06 08.30", "2 06 08.30", "3 06 09.65", "4 06 11.00", "5 06 15.05", "6 06 16.65", "7 06 17.80", "8 06 19.90", "1 07 08.95", "2 07 08.95", "3 07 10.55", "4 07 11.75", "5 07 16.80", "6 07 18.40", "7 07 20.05", "8 07 22.40", "1 08 09.60", "2 08 09.60", "3 08 11.45", "4 08 13.30", "5 08 18.20", "6 08 20.20", "7 08 22.05", "8 08 25.10", "1 09 10.25", "2 09 10.25", "3 09 12.35", "4 09 14.40", "5 09 19.75", "6 09 22.00", "7 09 23.95", "8 09 27.95", "1 10 10.90", "2 10 10.90", "3 10 13.25", "4 10 15.70", "5 10 21.35", "6 10 23.75", "7 10 26.30", "8 10 30.40" ); //this function makes sure the user has entered zone and weight //and then goes through the array and finds the correct zone and weight that //fits into - then sets the value of the charges field //to the correct charge function FindCharges(){ var Zone = document.getElementById("Zone").value; var Weight = document.getElementById("Weight").value; var Charges = 0 if (Zone.length != 1) { alert("You must enter Shipping Zone!"); document.getElementById("Zone").focus();} if (Weight.length != 1) { alert("You must enter shipping weight!"); document.getElementById("Weight").focus(); return; } else{ Zone = parseFloat(Zone); Weight = parseFloat(Weight); } var curRangeStart, curRangeEnd, Zone, Weight, Charges; for (var i = 0; i < PriorityMailArray.length; i++) { curRangeStart = parseFloat(PriorityMailArray[i].substring(0, 1)); curRangeEnd = parseFloat(PriorityMailArray[i].substring(2, 4)); if (Zone == curRangeStart && Weight == curRangeEnd) { Charges = parseFloat(PriorityMailArray[i].substring(5, 10)); document.getElementById("Charges").value = Charges; return; } } alert("You entered in an invalid zone!"); document.getElementById("zone").focus(); } </script> </head> <body> Enter shipping zone and weight: <input type="text" id="Zone" size="1" onkeydown="document.getElementById('Zone').value=''"> <input type="text" id="Weight" size="5" onKeyDown="document.getElementById('Weight').value=''"> <input type="button" onclick="FindCharges()" value="Find Charges"> Shipping is: <input type="text" id="Charges" size="5" disabled> </body> </html> Thanks for the help I would like to ask is it posible to add text from a text file to a text area on a page.. Philp if you read this i am not asking for a javascript code i am asking wether or not it can be done. P.s if your a nice person like philp is not and you want to private message me if you have one I'm having major pains trying to figure this out. I'm kind of new to Javascript, I need to open a text file from an external server, store each line in an array, then search that array for a certain word (HIGH), and if it exists then write something to the webpage, and if not, write something else. Here is what I have so far: Code: <html> <head> <title>Test</title> <script> <!-- function test(x) { if (wxd1txt.readyState === 4 && wxd1txt.status === 200) { // Makes sure the document is ready to parse and Makes sure it's found the file. var wxd1text = wxd1txt.responseText; var wxd1array = wxd1txt.responseText.split("\n"); // Will separate each line into an array var wxd1high = wxd1array.toString(); //Converting the String content to String //var highsearchreg = new RegExp("HIGH"); //var wxd1high = wxd1array[x].search(highsearchreg); document.write(wxd1high); if (wxd1high.search("HIGH") >= 0){ document.write("HIGH RISK");} else { document.write("NO RISK");} } } //--> </script> </head> <body> Hi! <script> <!-- var Today = new Date(); var ThisDay = Today.getDate(); var ThisMonth = Today.getMonth()+1; var ThisYear = Today.getYear(); var Hour = Today.getHours(); var Day2 = Today.getDate()+1; var Day3 = Today.getDate()+2; if (navigator.appName != "Microsoft Internet Explorer") { ThisYear = ThisYear + 1900;} if (ThisMonth < 10) { ThisMonth = "0" + ThisMonth;} if (ThisDay < 10) { ThisDay = "0" + ThisDay;} if (Hour == 2 || Hour == 22 || Hour == 23 || Hour == 0 || Hour == 1) { var wxHourd1 = 0600} else if (Hour >= 3 && Hour <= 10) { var wxHourd1 = 1300;} else if (Hour >= 11 && Hour <= 13) { var wxHourd1 = 1630;} else if (Hour >= 14 && Hour <= 16) { var wxHourd1 = 2000;} else if (Hour >= 17 && Hour <= 21) { var wxHourd1 = 0100;} //var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/"+ThisYear+"/KWNSPTSDY1_"+ThisYear+""+ThisMonth+""+ThisDay+""+wxHourd1+".txt"; var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/2010/KWNSPTSDY1_201005101300.txt" //(High risk day for testing) //document.write(wxurld1); //Use this to verify this section is working if (window.XMLHttpRequest) { wxd1txt=new XMLHttpRequest(); } else // IE 5/6 { wxd1txt=new ActiveXObject("Microsoft.XMLHTTP"); } wxd1txt.open("GET", wxurld1, true); wxd1txt.onreadystatechange = test(); // --> </script> </body> </html> When added to a webpage, nothing shows up except the "Hi!" and there are no errors in the Javascript Console in Google Chrome. Is this possible with Javascript, and if so, what am I doing wrong or not doing? Also, I have 2 URLs, one is a text file that has the HIGH text I want for an example, the other is the current file, which shouldn't have HIGH in it (unless the weather in the US turns really bad) hi, i have looked all over the internet but i can't find anything that works. All i want to do is simply read from a text file. Thanks Hello, I am building a web application that has quotes on it. I am planning on having all the quotes stored in a .txt file. A line space would separate the quotes. Example: "Blah Blah" "Idk what blah" "sure you do" Would this be using Javascript to pull the quotes from the txt file for use in my page be best? I need it to pull all the quotes. Reason for having it like this, I am also planning on having a random quote page where it just pulls 1 quote instead of showing all of them. I'm also open to other ideas here! David Faircloth Dear frnd I wanna read on html page , and i have script : " [I]<html> <head> <script type="text/javascript" language="javascript"> function Read() { var Scr = new ActiveXObject("Scripting.FileSystemObject"); var CTF = Scr .OpenTextFile("C:\\123.txt", 1, true); data = CTF .ReadAll(); document.write("<pre>" + data + "</pre>"); CTF .Close(); } </script> </head> <body onLoad="Read()" > </body> </html> [I] " But as its using activex control not allowing in all browser . Have you any other way with pure js to read the file contains ? or allowing activex in all browser ? Is allowing a button a create a text file a security issue? If so, how do I collect the names of users who have clicked a certain button?
Is there any possibility to write a text file using Chrome/FF? On the other words, writing a text file w/o using ActiveX. Thank you.
I'm pretty much lost at javascript, and unfortunately can use php to accomplish this, so here goes........ I have existing html page that includes a Week #. ie, 1, 2, 3, 5.... and so on. I'd like to be able to have a text, csv, or similar file that I can update on frequent basis that will list a Week # and than custom field of some type. (likely a date or unix time stamp). Is there a way to open a text file (or csv, etc) in javascript. Than be able to compare and get the correct data? Off the top of my head, I think its possible, and would involve something like the following? 1. Create a csv file like below 1, this is custom, my other custom 2, some more, and this too 3, and somthing, see spot run 2. Next would be have a javascript open and read the file. You would assign a variable name to each 1st, 2nd and 3rd item of each line. Than the script would loop through each line until it found a a match of Variable 1 to the Week your looking for. You could then parse out and use the other variables from that line. Any of that make sense? I hope to try and experiment some later today or tonight if I can, but javascript is still pretty foreign to me. |