JavaScript - Adding A Carriage Return Character To A String
Hi all
I am fairly used to programming, but not javascript, and I'm struggling a bit here... I am building a string inside a variable prior to printing it on screen as follows : Code: myclock += hours+':'+minutes; where "hours" and "minutes" are variables initialised elsewhere. How can I add a carriage return or new line character to the end of this line, so that anything else cocatenated to this variable is displayed on the next line. Thanks and have a nice evening. DeeJayBee Similar TutorialsHi Guys/Gals I am trying to do a small website for our family to keep track of each other's home address and etc.. using asp for the codes .. (its been ages since i indulge myself) i have 2 forms in which in FormA, i will key in the following address 666, ST Avenue #03-09 Anchor View Residence 123456 when i click on submit it shows this on FormB 666, ST Avenue #03-09 Anchor View Residence 123456 my question is how do i get it to be shown as 666, ST Avenue #03-09 Anchor View Residence 123456 in FormB in my formB.asp, for the particular code, all i wrote was Code: {Form.address} I am in need of advise, have been stuck here for the past 1 day, not knwing wat to start or how to start. Thank you I think I have the regex side of this script worked out. But I need help getting everything into an array for regex to read. Is there a way to use tokenizer to read everything before a carriage return? Each line should be added to an array for the regex to analyze and parse as needed. It's been ages since I touched tokenizer, so I forgot most of it. This is the text area in the html that the script should reference. Code: <textarea cols="60" rows="14" value="" id="paste" name="paste"></textarea> Thanks so much for any help you can give. Solved. thanks so much Phil!!!! So say if my string was.. Code: a = "Hello"; alert(a); How do I get it to say; Code: alert("ello"); So how do I take off the 'H' in this example.. Suppose I have the string 'ello'. I want to insert the letter 'h' in the beginning of that string. How do I do that without using a special function? I can only use the functions charAt and indexOf - anyone has any idea? Hello, I'm trying to remove one of the $ signs from this string below. I've gotten as far as removing them both. I'm having trouble removing one of them. Can someone help? 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=UTF-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script> $(document).ready(function(){ /*v = $("span.name").html().replace(/,/g,''); $("span.name").html(v);*/ v = $("div.test td").html().replace(/\$/g,''); $("div.test td").html(v); }); </script> <!-- <span class="name"><span class="gost">Yahoo</span>, </span>--> <div class="test"> <table><tr> <td>3-7 Business Days $$0</td></tr></table> </div> </body> </html> Hello all is it possible to strip leading (meaning at the VERY begining of the text) and trailing (anything at the end of the text) carriage returns with reg ex? so if smbody enters return return return start txt entry ----> keep all other returns in paragraph sloppy ending retrun return return it would remove the start and end returns I'd like to add it to this if possible. Code: comts = comts.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces low tech (validation script done trying to improve on it now) I don't understand the logic of Break, Return False, Return True. It was never really covered in our college class, and I see everyone using it. I got an A in the class, if that 'proves' that I really tried to apply myself. NOTE: I understand what the function is doing. I just don't understand WHEN to use break, return false or return true if the the translator can determine the conditional statements. PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } else return false; } if the the translator can determine the conditional statements, why not write it like this: PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; // what's the point for the 'break'? Won't the rest of the code be ignored since it passed the first condition? } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } // why not leave the last else out? is it just a 'safety' catch, in case something other than true or false is inputted? else return false; // what's the point? } Questions: Why use return true, if the translator knows it's ture? Why use "return false" if the translator knows it's false and the alert window has already gone up? why not use "break" to stop the code? Why use the "return false" at the end "else" statement? Hi room, Hey, I opened up the source code for this page in google chrome and since i'm learning javascript, i wanted see if i could "read" it and figure out what was going on. I'm am having the hardest time understanding "return false" and "return true". Could someone step me through this via interpreting this code (in bold typeface): Code: var DefaultValue = 'Search'; function clearSearch() { if (document.searchForm.q.value == DefaultValue) { document.searchForm.q.value = ''; } } function validateSearchHeader() { if ( document.searchForm.q.value == '' || document.searchForm.q.value.toLocaleLowerCase() == DefaultValue.toLocaleLowerCase() ) { alert('Please enter at least one keyword in the Search box.'); document.searchForm.q.focus(); return false; } return true; } Thanks! Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response Hi Im new to javascript and need some help with a project I have, the task I have is: Create a page that can take a bloke of text and out put the following o How many times each letter occurs o How many spaces o How many words o How many times each word occurs o A list of things that are not words or special characters I think maybe use an array but im not sure, like I said im new to this so not too sure on how to do it. I know it would read into a file say a txt file and sort through it this way, possibly using some kind of loop to read through all of the text before sorting it and I know it might use variables. I know how to kind of work through the task I have, but to actually implement the mechanics of the javascript is something that I then struggle with Thanks to all that help. Specifically i was wondering if anyone had any ideas on how to select the specific character when hovering over a word? I have not been able to find any documentation on this however, there is a demo site i found for a plugin that allows character selection. http://labs.bitmeister.jp/moamoa/demo.html i dont need anything that large and elaborate... Edit I'm pretty wel experinced with jquery, I know it's possible with jquery Hi all, I cant get this code to work because I do not know how to include the % character. Any help would be appreciated. My line break isnt working either Cheers, Adrian Code: rightButton.innerHTML = (rightOutcome1Prob+" chance of "+rightOutcome1+"\r\n else "+rightOutcome2); Hello all, I need assistance checking for valid characters in a username/password set up. I have been reading up on form validation but can't find exactly what I am looking for and need help deciphering what's going on. I have a list of accepted characters: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_@" a-z, A-Z, 0-9, dot, dash, underscore, and at. I want to then check an inputed string against that set and if a character is notin the accepted set, to send an alert. Here is what I have gathered so far: a for loop that increments through the values' .length - this is what checks each individual character. Then use of indexOf() can tell me which character is unacceptable. Now is where I am stuck and coming to you. Please help Hi i need a little help on a JavaScript program it ask the user for a keyboard character and a number of rows and columns to look like this RRRRR R___R R___R R___R RRRRR and also this in another program rrrrrr rrrrrr rrrrrr rrrrrr I currently have <html><body> <script type="text/javascript"> // Declare variables and constants var userInputText; // user input to go var numRow; // number of the rows var NumCol; // number of the columns var ES = ""; // empty string userInputText = prompt("Enter a keyboard character",ES); numRow = prompt("Enter the number of rows",ES); NumCol = prompt("Enter the number of columns",ES); //need a nested loop to draw the character box </script> </body> </html> if any one can help me finish this program i would appreciate it H, I'm trying to create an sms form. but I want the users to be able to monitor the characters and sms number as they type...taking 160 characters to be 1 page. pls I'll need help with coding this form to display characters left in 'ch_count' box and number of pages in the 'pages' box while typing in the 'message' textarea....hope it's clear enough...thanks Code: <p> <textarea name="message" cols="" rows="" id="message"></textarea> </p> <p> <input name="ch_count" type="text" id="ch_count" size="8" /> characters left <input name="pages" type="text" id="pages" size="8" /> pages </p> Ok I have a textarea field that is validated by Js, this textarea can and will contain the newline character Code: \n so I validate in JS Code: if(textareaname.value.length < 200) this hten goes through to my php where i also check before I place in to the Database using MYSQL Code: if( strlen($_POST['textareaname']) < 200 ) but my php is giving me a different string length from my javascript. It looks as if Javascript is counting a newline as 1 character and php is treating it as 2. I have checked my slashes, I have used various REgex to check these data amounts. I have also Googled around and there doesnt seem much around. Any ideas? Any suggestions as to how I can make php and javascript treat a newline as the same amount of characters? Thanks in advance. Hey Guys, I wanted to prepend a character to menu items when the mouse will hove over them. An example of this is seen on the website of Minivegas, he http://minivegas.net/ When you hover over a menu item at the top a slash appears in front. There seems to happen a couple of things to smoothen out the effect of prepending the character. I was looking for a similarly smooth way of adding a character in front of my menu items. Can anybody help me out on how to do this? I'm also unable to find out exactly how they did it on the Minivegas website. Anybody any ideas? Thanks in advance! Regards, Roy Hello HTML CODE TUTORIAL support, I am aryan. A student of engg. I want simple help in following code : It is simple 4 You and difficult 4 Me :unsu ================================================ <html> <head></head> <title>Mad </title> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>MAD</title> <script language="javascript" type="text/javascript"> function session() { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; var str = ''; for (var i=0; i<10; i++) { var b = Math.floor(Math.random() * chars.length); str += chars.substring(b,b+1); } document.frm.un.value = str; document.frm.s.value = str; document.frm.capt.src =" Free games - MAD.com init?w=120&h=40&f=png&s="+ str; document.getElementById("c").focus(); } </script> </head> <body> <form action='http://mad.com/ register' method='post' id='cI' enctype='text/plain'><p><input name='s' id='s' value='GENERATED 10 CHARACTERS HERE'' type='hidden'><p><input name='did' id='did' value='NEHA' type='hidden'><p><input name='pid' id='pid' value='twinkle' type='hidden'><p><input name='cid' id='cid' value='twinkle' type='hidden'><p><input name='l' id='l' value='en' type='hidden'> <p> <b>USERNAME</b><br> <input name='un' id='un' value='aliya_loves7' ><p><b>PASSWORD</b><br> <input name='pw' id='pw' value='Iaminhell8*'></p><p> <img src='http://mad.com/init? w=120&h=40&f=png&s=GENERATED 10 CHARACTERS HERE'></p><p> captcha <br><input name='c' id='c'><br><br><input name='send' value=' CREATE ' type='submit'></ form></font> </head> ================================================== In this code i wrote code in italic font. Which is modified by me And i want to know it is wrong or right ? I want to know exact what is wrong here. I tried many times but getting error. And i also want to know When i click on CREATE button, <img src='http://mad.com/init? w=120&h=40&f=png&s="GENERATED 10 CHARACTERS HERE> This value want to change automatically for next session But dont open next page i want to change this in that page likes Refresh Captcha when i press CREATE button One more thing I Have Four input Value ABHI,AKKI,SIMRAN,PRINCE I want to replace this value into NEHA input value. [You can see in code] I also want to change this value when Img src refreshed Please Help me |