JavaScript - Format Bullets Hierarchy
i try to create a simple editor. But i'm having problem with bullets hierarchy
Code: <html> <body> <style type="text/css"> #preview,#editor,#editor-html{ width:500px; height:250px;} #preview{ clear:both;background:#eee; } #editor,#editor-html{ float:left;} </style> <div id="preview"></div> <p><textarea id="editor" ></textarea></p> <p><textarea id="editor-html"></textarea></p> <script type="text/javascript"> var oEdit = document.getElementById('editor'); var oCheck = document.getElementById('editor-html'); var oPrev = document.getElementById('preview'); function doBullets(s){ var s = this.value; var r = /\n{2}\s#\s[\s\S.]*?\n{2}/g; var a = s.match(r); var step = 0; var bCount = false; if(a){ a = a.toString(); a = a.split(/\n{2}/g); var iL = 0; var iMax = 0; for(var j=0;j<a.length;j++){ if(a[j].match(/^\s#\s/)){ var iF = s.indexOf(a[j]); var iL = a[j].length; var html = ''; var list = a[j].split(/\s#/); for(var i=0;i<list.length;i++){ if(list[i]){ var level = list[i].match(/^\s?#*\s/); level = level?(level[0].length):0; var txt = list[i].replace(/^\s?#*\s/,'').toString().replace(/\n?$/,''); if(level > step){ step++; iMax++; html = html.replace(/<\/li>\n?$/,''); html += '\n<ul>\n'; } if(level < step){ step--; html += '</ul>\n'; } var iCounter = iMax-level; if(iCounter){ for(var y=0;y<iCounter-1;y++){ html += '</li></ul></li>'; } } document.title = level+' '+step+' '+iMax+' counter:'+iCounter; html += '<li>'+txt+'</li>\n'; } } s = s.substring(0,iF)+html+s.substring(iF+iL,s.length); } } } oPrev.innerHTML = s; oCheck.value = s; } oEdit.onkeyup = doBullets; </script> </body> </html> Please help... Similar TutorialsI came across this really interesting experiment. http://www.romancortes.com/blog/a-tr...o-the-beatles/ What I was wondering was does anyone know what the data used is from? I mean what type of image format it is. I've tried to figure it out but I just can't find what it is. I see how the script works, but I was wondering if the author used some available image format or if he created the image data from scratch. Thanks for any advice you might be able to offer. I am trying to get my script working in FF, IE and Opera but the getAttribute isn't working for me. The domain name isn't getting picked up I have tried this: var dom_name = document.getElementById('dom_nm').getAttribute("value",2); and this: var dom_name = document.getElementById('dom_nm').getAttribute('value'); After this I use the domain name like this: Code: if (per2 == 0) { item_desc = "Domain Name and DNS set up. Domain: "+dom_name+" Period: "+per1+"year"+" No Privacy."; } if (per2 > 0){ item_desc = "Domain Name and DNS set up. Domain: "+dom_name+" Period: "+per1+"year"+" Including: Privacy: "+per2+"year."; } document.getElementById('item_pay').setAttribute("value","item_desc"); ( I also tried: Code: document.getElementById('item_pay').setAttribute('value') = item_desc; but that didn't seem to work either ) The HTML is like this: Code: <div style="margin: 5px auto;"> <table> <th>Your New Domain Name Order</th> <tr><td>Product</td><td>Cost</td><td>Years (max. 10)</td><td style="text-align: right;">Total Cost</td></tr> <tr><td id="dom_nm" value="John.Doe"><?php echo "Domain: $N_dom.$N_tld" ?></td><td id="price" value = '<?php echo "$priceN" ?>' ><?php echo $priceN ?></td><td><input style="background-color: yellow; font-weight: bold;" type='TEXT' id="per_1" size = '10' value = '<?php echo "$period_1" ?>' ></td><td><input type='TEXT' id="total_1" style="text-align: right;" value = '<?php echo "$total_1" ?>'></td></tr> <tr><td>Domain Privacy</td><td>8.70</td><td><input style="background-color: yellow; font-weight: bold;" type='TEXT' id="per_2" size = '10' value = '<?php echo "$period_2" ?>'></td><td><input type='TEXT' id="total_2" style="text-align: right;" value = '<?php echo "$total_2" ?>'></td></tr> <tr><td>Total Order.</td><td> --- </td><td> --- </td><td><input type='TEXT' id="total_3" style="text-align: right; font-weight: bold;" value = '<?php echo "$total_3" ?>'></td></tr> </table> </div> The result is that I get a zero ( 0 ) where the domain should be. Like this: Domain Name and DNS set up. Domain: 0 Period: 2year Including: Privacy: 2year. Plus Free Blog Install. Any ideas what I am doing wrong ? Thanks I've been trying to change the way a date appears. The JS gives the date Easter will fall in a particular year. That works but the format that appears is this; Sun Apr 24 00:00:00 EDT 2011 I'm trying to get it to read like this: Sunday, April 24, 2011 I've been racking my brain all morning and can't seem to get it right. Very limited experience in JS doesn't help either. Could somebody take a look and see where I messed up. Thanks in advance. George Code: easterYear = 2011; var a, b, c, d, e, f, g, h, i, k, l, m, easterMonth, easterDate; a = parseInt(easterYear % 19); b = parseInt(easterYear / 100); c = parseInt(easterYear % 100); d = parseInt(b / 4); e = parseInt(b % 4); f = parseInt((b + 8) / 25); g = parseInt((b - f + 1) / 3); h = parseInt((19 * a + b - d - g + 15) % 30); i = parseInt(c / 4); k = parseInt(c % 4); l = parseInt((32 + 2 * e + 2 * i - h - k) % 7); m = parseInt((a + 11 * h + 22 * l) / 451); easterMonth = parseInt((h + l - 7 * m + 114) / 31); easterDate = parseInt(((h + l - 7 * m + 114) % 31) + 1); var dayName = new Array ("Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"); var monthName=new Array ("January","February","March","April","May", "June","July","August","September","October", "November","December"); var now = new Date(); var gplMonth = monthName[easterMonth-1]; var gplDay = dayName[0]; //gplDay ; var gplDate = new Date(); var gplDt = gplDate.getDate(); document.write(new Date(easterYear , easterMonth - 1, easterDate) ); // Original line document.write('<br />' ) document.write( gplDay + ", " + gplMonth + " " + easterDate + ", " + easterYear) document.write('<br />' ) document.write(gplMonth + " " + easterDate ) document.write('<br />' ) 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; } Hi, I have a textarea element and I fill it with text. But I want to insert newlines to seperate some of the words in the textarea. I tried to use '\r' or '\n' or '\r\n', but none of them works. Code: var textArea = document.createElement('textarea'); textArea.value = 'good' + '\n' + 'morning'; The newline has no effect, it still show 'good morning'. Why? And also, I am going to write these words in the textarea into database and later retrieve them back from database to another textarea, should I keep the newline characters or is it better use some other delimiter? Many thanks. Alright so I've been searching around trying to figure out how to change the date format, the way I have seen it the most is like Code: var d=new Date(); var datestring=d.getdate + d.getMonth + d.get Year I am new to javascript and this is the first script I have written on my own so this is what it does. It is supposed to display the date that a shipment should arrive on with 2 day shipping through ups so it skips weekends. It displays the date after either adding 2 days or more depending on the day of the week. But the way the date is formatted really needs to be changed. So if any one can suggest maybe how to tie in the above code with mine that would be great. Code: <script type="text/javascript"> var d=new Date(); var day=d.getDay(); if (day <= 3){ d.setDate (d.getDate() + 2); } else if (day == 4) { d.setDate (d.getDate() + 4) } else if (day == 5){ d.setDate (d.getDate() + 4); } else if (day == 6) { d.setDate (d.getDate() + 3); } document.write("Your card should arrive on " + d); </script> Hello. I have got this kind of array: Code: $days = array('Monday' => '2012-03-19', 'Tuesday' => '2012-03-20' ); I'm iterating like this: Code: foreach($days as $key => $value){ echo '<a href="javascipt:confirmDelete('.$value.');">Delete</a>'; } Script: Code: function confirmDelete(day) { if (confirm('Delete?')) { window.location.href = 'processDay.php?action=delete&day=' + day ; } } While i hover over the link with coursor, it show it good: javascript:confirmDelete(2012-03-19), but when I submit the delete confirmation, i get &day=1987. Where is the problem? Dear Experts I have following codes Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <title>Numeric Textbox Sample</title> <style type="text/css"> #box1 {width:200px;height:170px;border:1px solid green;background:#e3eeff;padding-top:20px;} .button {width:100px;margin-top:0px;} body { margin:0; margin-top:100px; } </style> <script language="javascript"> function NumericDotOnly() { var key = window.event.keyCode; if (((key >47) && (key <58)) || (key==46)) window.event.returnValue = true; else window.event.returnValue = false; } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); } </script> </head> <body onload="form2.text1.focus()" > <center> <p>I need following format<br> 99,999,999.99<br> </p> <div id="box1"> <form name=form2> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td>Amount</td> <td><input type=text name=text1 size=15 value="" onkeypress="NumericDotOnly ()";onblur="formatCurrency(this.value)"> </td></tr> <tr><td>Tax</td> <td><input type=text name=text2 size=15 value="" onkeypress="NumericDotOnly()";onblur="formatCurrency(this.value)"></td></tr> <tr><td>Result</td><td><input type=text name=text3 size=15 value="" disabled></td></tr> </table> <hr> <input class="button" type=button name=command1 value="Plus" onclick="form2.text3.value=parseFloat(form2.text1.value)+parseFloat(form2.text2.value)"><br> <input class="button" type=button name=command8 value="Focus" onclick="form2.text1.select()";"form2.text1.focus()"><br> <input class="button" type=reset name=command9 value="Reset"> </form> </div> </center> </body> </html> Please help me to apply following format 99,999,999.99 Thanks in advance We format euro currency as 1.000.000,00 (just the opposite of USD). Anyone who could give me a script that changes the input into this format? I tried 'replace' with a regular expression, but my regexes don't work. Is there a built in function to format a number to 2 decimal places and to add commas like below. 2,222.33 30,033.98 1,222,345,99 Hi all, I have a web form. I use a simple function to generate a letter ouput based on the form fields and populate them into a word doc for printing. Below is a basic example, but you get the idea. Code: function createDocument() { strDoc = "\n\n" strDoc += "Hello there!\n" strDoc += "Answers to form stuff goes here\n" var w =new ActiveXObject("Word.Application"); w.Visible=true; w.Documents.Add(); w.Selection.TypeText("" + strDoc); } Note this is only intended to be used on IE8. As it stands, the ouput generates and formats exactly as I want bar two things: 1) Does anyone know how I can get some of the text to bold? I've tried everything I can think of (html tags, escape characters etc etc). Is there a way to open a word window in rtf perhaps? 2) Does anyone know how I can insert a small image (a signature in gif or jpg) into the document? I can use a browser window instead of word, which formats, bolds, images etc, however I then get the issue of headers/footers when printing. I cannot disable headers everytime I want to print a letter, it's not practical. Any advice would be greatly appreciated Cheers! Hello! First of all, sorry my bad english. (and javascripting skills...) I have a problem with date formatting! My code is supposed to get the day of the week from date format like dd.mm.yyyy (01.01.2010, 31.12.2010) but it only works if date format is like "28 December, 2000". Code is he Code: <script type="text/javascript"> function getTheDay(aText) { myDays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] myDate=new Date(eval('"'+aText.value+'"')) document.form1.textDay.value=myDays[myDate.getDay()] } </script> <form name="form1" id="form1" method="post" action="" enctype="text/plain"> <input type="text" name="textDate" id="textDate" value="" size="25" onchange="getTheDay(this.form.textDate)" /> <br /> <input type="text" name="textDay" size="25" maxlength="25" /> </form> Original code: http://www.trans4mind.com/personal_d...ript/time2.htm Can anyone help me? I have tried everything what i have find from google... Thanks to you all who help me with this! -Roosterr Hello, I want to change time format from 12 to 24 hours and remove AM and PM in this script. Anybody can help me? Code: <style type="text/css"> /*<![CDATA[*/ #clock { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-size:16px; color:#030; padding-top: 24px; text-align:center; } /*//]]>*/ </style> <script type='text/javascript'> //<![CDATA[ var dayarray=new Array('Svē','Pir','Otr','Tre','Cet','Pie','Ses'); var montharray=new Array('01','02','03','04','05','06','07','08','09','10','11','12'); function getthedate(){ mydate=new Date(); year=mydate.getUTCFullYear(); day=mydate.getDay(); month=mydate.getMonth(); daym=mydate.getDate(); if(daym<10) { daym='0'+daym; } hours=mydate.getHours(); minutes=mydate.getMinutes(); seconds=mydate.getSeconds(); dn='AM'; if(hours>=12) { dn='PM'; } dn='AM'; if(hours>=12) { dn='PM'; } if(hours>12){ hours=hours-12; } if(hours==0){ hours=12; } if(minutes<=9) { minutes='0'+minutes; } if(seconds<=9) { seconds='0'+seconds; } cdate=dayarray[day]+', '+daym+'-'+montharray[month]+'-'+year+', '+hours+':'+minutes+':'+seconds+' '+dn; document.getElementById('clock').firstChild.nodeValue=cdate; setTimeout('getthedate()',1000); } window.onload=function() { getthedate(); } //]]> </script> Thanks. Hello, Firstly - relatively new to javascript. I have seen many examples of code that will return a passed value in a currency format - however I have a sales form that is calculating values via a function in the text boxes I want formatted with a currency ($) symbol. The function that is called is not passing any values, and returning a calculation of the form subtotals per item, and then total sales figure. Can anybody give me any hints on format these cells to a currency value? I can give examples of how my code is currently if required. Thanks in advance Hi All, I have a snippet of Javascript that changes date format from yyyy/mm/dd 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 want it to return the format as dd/mm/yy (the last two number of the year rather than the full four). Is this possible to do? Thanks, Neil How would I get the local time of a pc using JavaScript in dd-mm-yyyy format ?
I'm trying to add some css tags (<strong>, <em> etc) to an entire paragraph <p> that contains a custom word, for example a paragraph like this <p>Title:....</p> This could be easily done for the custom word only with a var.str and document write. I would be grateful if you could post the entire code. Hi Guys, I'm looking for a way to convert a number in to currency format so 10000000 is 10,000,000 etc... i found this code and was hoping someone could advise how to tweak it so that it works automatically without having to hit a button i.e. I will be passing a value dynamically to the code and want it evaluated without the user clicking anything if the code was like var="10000000" <-the number I dynamically pass in and output 10,000,000 You probably guessed Javascript aint my forte. Thanks http://www.designerwiz.com/JavaScrip...ncy_format.htm Code: <!-- // == This Script Free To Use Providing This Notice Remains == // // == This Script Has Been Found In The http://www.DesignerWiz.com Javascript Public Archive Library == // // == NOTICE: Though This Material May Have Been In A Public Depository, Certain Author Copyright Restrictions May Apply == // --><script language="JavaScript" type="text/javascript"> <!-- Begin function checkNum(data) { // checks if all characters var valid = "0123456789."; // are valid numbers or a "." var ok = 1; var checktemp; for (var i=0; i<data.length; i++) { checktemp = "" + data.substring(i, i+1); if (valid.indexOf(checktemp) == "-1") return 0; } return 1; } function dollarAmount(form, field) { // idea by David Turley Num = "" + eval("document." + form + "." + field + ".value"); dec = Num.indexOf("."); end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00"); Num = "" + parseInt(Num); var temp1 = ""; var temp2 = ""; if (checkNum(Num) == 0) { alert("This does not appear to be a valid number. Please try again."); } else { if (end.length == 2) end += "0"; if (end.length == 1) end += "00"; if (end == "") end += ".00"; var count = 0; for (var k = Num.length-1; k >= 0; k--) { var oneChar = Num.charAt(k); if (count == 3) { temp1 += ","; temp1 += oneChar; count = 1; continue; } else { temp1 += oneChar; count ++; } } for (var k = temp1.length-1; k >= 0; k--) { var oneChar = temp1.charAt(k); temp2 += oneChar; } temp2 = "$" + temp2 + end; eval("document." + form + "." + field + ".value = '" + temp2 + "';"); } } // End --></script> <center> <form name=commaform>Enter a number then click the button: <input type=text name=input size=10 value=""> <input type=button value="Convert" onclick="dollarAmount(this.form.name, 'input')"> <br><br> or enter a number and click another field: <input type=text name=input2 size=10 value="" onBlur="dollarAmount(this.form.name, this.name)"> </form> this code is formatting the price like that 500 000 but i need to price format like this 500.000 so i need dot instead space code at below PHP Code: <html> <head> <script type="text/javascript"> window.onload = attachEvents; function attachEvents() { document.getElementById('myInput').onkeyup = reformatNumber; } function reformatNumber() { // No error checking. Assumes only ever 1 DP per number var text = this.value; // Strip off anything to the right of the DP var rightOfDp = ''; var dpPos = text.indexOf('.'); if (dpPos != -1) { rightOfDp = text.substr(dpPos); text = text.substr(0, dpPos); } var leftOfDp = ''; var counter = 0; // Format the remainder into 3 char blocks, starting from the right for (var loop=text.length-1; loop>-1; loop--) { var char = text.charAt(loop); // Ignore existing spaces if (char == ' ') continue; leftOfDp = char + leftOfDp; counter++; if (counter % 3 == 0) leftOfDp = ' ' + leftOfDp; } // Strip leading space if present if (leftOfDp.charAt(0) == ' ') leftOfDp = leftOfDp.substr(1); this.value = leftOfDp + rightOfDp; } </script> </head> <body> <form> <input type="text" id="myInput" /> </form> </body> </html> Does JavaScript have an easy of converting an ordinary integer like 135 into a time format like 02:15? I'm working on a timer that handles the backend with just a plain integer that counts down every second but it needs to output looking like a clock.
|