JavaScript - Count On Returns (gaps) Text Counter - Help
Hi,
I have the below code it works, but there a problem. If you press return to drop a line it counts that as a letter/number. Is there a way to fix it? <html> <head> <title></title> </head> <body> <script language="JavaScript"> function CheckCount() { var maxChar = 2000000; if(document.frmMain.txtDetail.value.length > maxChar) { return false; } else { document.frmMain.txtCount.value = document.frmMain.txtDetail.value.length; } } </script> <body> <form name="frmMain" method="post"> <textarea name="txtDetail" cols="40" rows="5" id="txtDetail" onKeyUp="return CheckCount()"></textarea> <br> <input name="txtCount" type="text" id="txtCount" style="width:65px;" value="0"> </form> </body> </html> Similar TutorialsI'm just starting out learning and have sort of given myself a couple of basic problems to solve. I pretty quickly found something that's apparently hard to Google. I've made a page that shows a counter number, starting at 0, with buttons that will increase or decrease the number by 1 or 10. So I'd like to figure out how to show that number in red when it is a negative number and in green when it is a positive number. I've tried a couple of things, including an if... else, but here's my latest crack: Code: var counter=0; function countUp() { lastCounter=counter; counter++; display(); } function countDown() { lastCounter=counter; counter--; display(); } function tenUp() { lastCounter=counter; counter+=10; display(); } function tenDown() { lastCounter=counter; counter-=10; display(); } function lastNumber() { counter=lastCounter document.getElementById("number").innerHTML=lastCounter; } function display () { number=counter+''; switch(counter) { case counter== 0; document.getElementById("number").innerHTML=number.fontcolor(white); break; case counter> 0; document.getElementById("number").innerHTML=number.fontcolor(green); break; case counter< 0; document.getElementById("number").innerHTML=number.fontcolor(red); break; } //end switch } //end display I suspect that what I'm doing totally wrong has to do with how I'm describing the case or with calling one function inside another function, since it works up until I start messing with that (had the document.getElementByID stuff in the countUp, countDown, etc., functions before) but I don't know. Thanks in advance for any help you can offer. Hi, I have a form in which I preset some text inside a readonly, disabled textarea using javascript ('data' being the text): document.getElementById("link_of_current_view2").value = data; However, once I call my .php script to process the form, the element is null. How do I get it to pass along that data, which is in the textbox when the user views the form? Code: <div id="sendlink" class="contact_form" style="z-index:10;"> <a class="close" onclick="document.sendlink_form.reset();return false">CLOSE</a> <form id='sendlink_form' name='sendlink_form' method="post" action="sendlink.php" > <label for="link_of_current_view2">Link: </label> <textarea id="link_of_current_view2" name="_of_current_view2" class="link_of_current_view" rows="2" disabled="disabled" wrap="soft" size="58" value="" readonly="readonly" value=/></textarea> <input type="image" src="images/forms/submit.png" value="Submit" alt="Submit"> <a onclick="javascript:reset_sendlink()" style="cursor:pointer"><img src="images/forms/reset.png"></a> </div> Thanks for reading! Okay, 3 questions I'm afraid, all in reference to the JQuery Galleria on this page: http://digital.tmhcentral.com/pratt/a... Apologies for my explanations as I am a newby to anything beyond html & css. 1. I have a number of images placed in my html page simply using the img tag. When the page is loading I see these images stacked (full size) for a few seconds before galleria loads and then begins to convert them into thumbnails. Any idea how to hide the images on the page but only to appear in the galleria as the images start to load as thumbnails? 2. I wish to have the same 5px (horizontal) gap between each thumbnail. However my images are of different sizes and have been optimized to a max width or max height. I do not wish for the thumbnails to be cropped so have set: thumb_crop: false, This has now visually created an inconsistent horizontal space between each thumbnail (highlighted in pink to show the gap left and right of each one). I have already attempted to change the thumbnail width to auto in the css, but with no success. How do I remove the 'excess' left & right space from each thumbnail so that the gap appears consistent? 3. Lastly, upon page load, is it possible to hide the main stage image until a thumbnail is selected? I wish to initially display some text (where the main image sits) which is then replaced with the main image when the user clicks on one of the thumbnails. I would appreciate help on any of the above. Thanks in advance, Paul I need to do an input text validation which include opening parenthesis and closing parenthesis, what I need to validate is the opening parenthesis match with closing parenthesis. Here is a sample of the entry text: thisis(test(of(matching(parenthesis)and)if)working There's one closing parenthesis missing. I would like to warn the user to correct it before submit, but not quite sure how to do it with javascript. Please advice. Thanks JT Code: <script> // Declared Constants MORSE_ALPHABET = new Array ( '.-', // A '-...', // B '-.-.', // C '-..', // D '.', // E '..-.', // F '--.', // G '....', // H '..', // I '.---', // J '-.-', // K '.-..', // L '--', // M '-.', // N '---', // O '.--.', // P '--.-', // Q '.-.', // R '...', // S '-', // T '..-', // U '...-', // V '.--', // W '-..-', // X '-.--', // Y '--..' // Z ); CHAR_CODE_A = 65; var CTS = prompt('Enter Morse code','here') var inMessage = CTS.split(' '); searchLocation(inMessage,MORSE_ALPHABET) function searchLocation(targetValue, arrayToSearchIn) { var searchIndex = 0; // Iterative counter for(i=0;i < targetValue.length;) { targetValue = targetValue[i]; // Search until found or end of array while( searchIndex<arrayToSearchIn.length && i != targetValue.length && arrayToSearchIn[searchIndex]!=targetValue ) { i++ searchIndex++; } if(searchIndex<arrayToSearchIn.length) { return String.fromCharCode(CHAR_CODE_A + searchIndex); } else { return -1; } } } document.writeln(searchLocation(inMessage,MORSE_ALPHABET)); </script> <head> </head> <body> </body> This is my code and i have figured it to create an array from the prompt and then use the function to return the first array it finds but i cant seem to make it go on to the next index of the array. I know that when you return a value the function closes and i have tried to store my return in a variable but its not working the way i want it to or I'm not writing the correct command or is there away to do multiply returns, i think what i need to do is simply but i have been staring at this screen for a while now and just cant see it. Please help me. Thanks Hi all. New here as you can probably tell, and I have a problem... I want to know how to find out the viewport height in IE. I have been trying to use document.body.clientHeight, which is supposedly exactly what I am after, but the results were always way too small to be the correct one. As a test, I whacked a div in my page and made it 4000px tall, and ran document.body.clientHeight from IE's debugger and it returned a number over 4000px. It seems as thought clientHeight is actually returning the total height of the document, not the viewport size. Thanks for any help. Suppose we have following javascript codes: Case 1. var foo = function () { var x = "hello"; var bar = function () { alert(x); } return bar; } var bar_ref= foo(); document.write(bar_ref()); // it pops up "hello" and print-outs "undefined". If we modified above code slightly, shown as follow: Case 2. var foo = function () { var x = "hello"; var bar = function () { alert(x); } return bar(); } var bar_ref= foo(); document.write(bar_ref()); // it only pops up "hello". As you can see, Case 2 modified the return value from "return bar" to "return bar()," which won't cause the "undefined" output. To me, it looks like when the JS interpreter executes the line "bar_ref();" it triggers the execution of function "foo", besides both "return bar" and "return bar()" do the same job which is to execute function body of "bar". The only difference is that after the execution of function bar, its function body does not exist anymore, so when the interpreter executes the line "return bar;" it follows the function identifier "bar" and ends up with "undefined". This is why the Case 1 gives us "undefined", but I am not quite clear about why the Case 2 can trace down to the function body of "bar". Do you have any ideas about such difference outputs? Dan hi here is a code i use to calculate distance b//w 2 places using google api... it works perfectly and shows the results in the html but when i add a return statement at the end of the function showlocation() it returns undefined.. why it is so.. how to resolve it??? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta name="robots" content="noindex,follow" /> <title>Calculate driving distance with Google Maps API</title> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAMK3PClIOG6IUkYprx4EfNxSY_HQRLXr6AGORx7Qh39w3-je8JxRROt5eJTcDPJ9nGnVn9xXKTQ2l8Q" type="text/javascript"></script> <!-- According to the Google Maps API Terms of Service you are required display a Google map when using the Google Maps API. see: http://code.google.com/apis/maps/terms.html --> <script type="text/javascript"> var geocoder, location1,addr1,addr2, location2, result1,gDir; function coolAl(add1,add2) { addr1=add1; addr2=add2; var result= return initialize(); showLocation(); alert(result); } function initialize() { geocoder = new GClientGeocoder(); gDir = new GDirections(); GEvent.addListener(gDir, "load", function() { var drivingDistanceMiles = gDir.getDistance().meters / 1609.344; var drivingDistanceKilometers = gDir.getDistance().meters / 1000; result1=location1.address + ' (' + location1.lat + ':' + location1.lon + ')/' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')/' + drivingDistanceKilometers + ' kilometers'; document.body.innerHTML=result1; return drivingDistanceKilometers; }); } function showLocation() { geocoder.getLocations(addr1, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; geocoder.getLocations(addr2, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the second address"); } else { location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; gDir.load('from: ' + location1.address + ' to: ' + location2.address); } }); } }); } </script> </head> <body onload="coolAl('pune','mumbai')"> </html> RESOLVED Thank you! Greetings all! Im looking for some help regarding responseText, so please have a look im so mad right now because i have been struggeling for hours XMLHttpRequestObject.responseText returns correct value when i do alert(XMLHttpRequestObject.responseText); see line PHP Code: var fnWhenDone = function (XMLHttpRequestObject) { alert(XMLHttpRequestObject.responseText); }; But problem is that i want to save down the response to a variable... so i try to change it into PHP Code: var fnWhenDone = function (XMLHttpRequestObject) { varTest = XMLHttpRequestObject.responseText; }; When i try to alert varTest later i get "Undifined"... im pretty new to javascript and have been stuck for hours ... See full code below PHP Code: var myConn = new XHConn(); if (!myConn) { alert("XMLHTTP not available. Try a newer/better browser."); } var fnWhenDone = function (XMLHttpRequestObject) { alert(XMLHttpRequestObject.responseText); }; myConn.connect("validateSearch.php", "POST", "foo=bar&baz=qux", fnWhenDone); function XHConn() { var xmlhttp, bComplete = false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }}} if (!xmlhttp) return null; this.connect = function(sURL, sMethod, sVars, fnDone) { if (!xmlhttp) return false; bComplete = false; sMethod = sMethod.toUpperCase(); try { if (sMethod == "GET") { xmlhttp.open(sMethod, sURL+"?"+sVars, true); sVars = ""; } else { xmlhttp.open(sMethod, sURL, true); xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4 && !bComplete) { bComplete = true; fnDone(xmlhttp); }}; xmlhttp.send(sVars); } catch(z) { return false; } return true; }; return this; } I know there is probably going to be an embarrassingly simple answer to my issue (like I am pointing to the wrong place in the DOM) but here goes. Why is the value of overflow not being returned by the below script? Code: <style type="text/css"> div.fbOverflow_Scroll { position:absolute; top:20px; left:20px; z-index:27; overflow:scroll; overflow-x:hidden; height:30px; width:100px; background-color:#FFB60D; border:1px Solid #000000; } </style></head><body><form method='post' enctype='multipart/form-data' id='myForm' name='myForm'> <!-- **** lab(Box10pt, fbOverflow_Scroll, , Extra=) --> <div class='fbOverflow_Scroll' id='fbOverflow_Scroll' position=relative > This is stuff inside of a little scrolling area of the form</div> <script language="JavaScript"> alert(document.getElementById('fbOverflow_Scroll').style.overflow); </script> </form> Hi all, I have a simple XML file that looks something close to this: Code: <presence id="12345"> <status>in a meeting</status> <priority>1</priority> </presence> <x> <picture>blahblah</picture> </x> <x> <hash>string</hash> </x> I need javascript to pull the status from this file. Here's what I have for that: Code: <span id="login_status"></span> <span id="secondlogin_status"></span> <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","https://www/user1.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("login_status").innerHTML= xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; document.getElementById("priority").innerHTML= xmlDoc.getElementsByTagName("priority")[0].childNodes[0].nodeValue; xmlhttp.open("GET","https://www/user2.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("secondlogin_status").innerHTML= xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; document.getElementById("second_priority").innerHTML= xmlDoc.getElementsByTagName("priority")[0].childNodes[0].nodeValue; </script> Here's my problem: If my xml file only has the one "parent" (meaning: Code: <presence id="12345"> <status>in a meeting</status> <priority>1</priority> </presence> ) this works WONDERFULLY. However, when the second and third "parents" are added (<x>), the script returns blank output in the spans. I feel almost certain my issue is related to this: http://codingforums.com/showthread.php?t=140810 but I've tried to switch that around but it doesn't seem to provide any different results. If you require a bit more info on the project itself, here's a rundown: This xml file is created by an internal chat app at my office. Each employee has their own xml file listing their current availability and status (hence "in a meeting"). This will be used to determine the availability of certain individuals in the building without having to be logged in to the chat app. That's why there's multiple xml files going to be used (roughly 10-15 in the end). Hi All, could you please help me. A have a little program and i need to count somehow how many times a while loop is ran. how could i do that? Thanks for your help Hey Everyone, I'm working on a counter. I have two images - each with their own click count. Right now each time the page loads the counter goes back to zero. I would assume I need some kind of server side coding. Any recommendations? Here's what I have so far. <html> <head> <script type="text/javascript"> var counter = 0; function increaseloveit() { counter += 1; document.getElementById('loveit').value = counter; } var counter = 0; function increasehateit() { counter += 1; document.getElementById('hateit').value = counter; } </script> </head> <body> <form> <a href="#" onclick="javascript:increaseloveit();"><input type="button" value="Love It!" name="loveit" onclick="" /></a><input id="loveit" value="0" size="2" /></form> <form> <a href="#" onclick="javascript:increasehateit();"><input type="button" value="Hate It!" name="hateit" onclick="" /></a><input id="hateit" value="0" size="2" /></form> </body> </html> I am trying to use the Jquery loader (this ends when page loads) but I want it to load how many seconds the page took. (using the clean preloader) $( "#progressbar" ).progressbar({ value: setTimeout("seconds++",10000000) }); but getting "anything" to work in the "VALUE" has been such a pain. any one that knows how to create a timer to add to the value so that preload will keep loading? or if even possible? thanks I have the following codes and it seems to work well but when exiting the site and re-entering it resets the values to 0 again. I am not sure how to proceed with this, been considering cookies but what if the user clears there cookies, I then looked at PHP but not understanding that to well at this stage. Javascript Code: // Function to count clicks on links var clicks1 = 0; var clicks2 = 0; var clicks3 = 0; var clicks4 = 0; function link1(){ document.getElementById('clicked1').value = ++clicks1; } function link2(){ document.getElementById('clicked2').value = ++clicks2; } function link3(){ document.getElementById('clicked3').value = ++clicks3; } function link4(){ document.getElementById('clicked4').value = ++clicks4; } HTML Code: Code: <tr valign="middle" align="center"><td colspan="1"><a target="_blank" href="http://mistiquestormelectronics.webs.com/" onclick="link1()"><img src="site_graphics/reinet.jpg" alt="Mistique Storm" width="120" height="90" /></a></td> <td colspan="2" align="left"><p>For all your Electronic equipment needs.</p></td> <td colspan="1" width="8%"><input id="clicked1" style="color: #000000; font-weight:bold; border-style: none; font-family: arial; background-color: #00FF00; text-align: center;" readonly="readonly" size="10" onfocus="this.blur();" value="0" ></td></tr> Any ideas, suggestions. Please Help? I need help with a counter that will either display a different image everyweek or change text every week. The scenario is a counter will be on the top right corner of the page, and every week the number will change from 1 to 2 to 3... to 52... I searched on this forum for answers, i found some similar for a different day counter. Any help would be great! So I'm really new to javascript and html. The most advanced thing Ive made was probably a Russian rullete simulator, but I need help with this one program Im working on. So if anyone could tell me whats wrong with this, I would appreciate it! <html> <head> <font size="4">Click the button below as many times as you can</font> <br> <script type="text/javascript"> var clicks=0 function count() { clicks=clicks+1; } </script> </head> <body> <input type="button" value="Click Me" OnClick="count()"> <br> <p>Clicks: <script type="text/javascript"> document.write(clicks); </script></p> </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) Hi, I found this regular expression on the internet and it works fine when I test it in various validators on the web. Code: ^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$ It's purpose is to validate dates entered as mm/dd/yyyy, m/dd/yyyy, mm/d/yyyy or m/d/yyyy. When I try it with the code below it always returns null. Code: function isValidDate(/* String */ p1_date) { var x = "^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$"; var re = new RegExp(x); var myValid = p1_date.match(re); alert("p1_date: " + p1_date + "\nmyValid: " + myValid); return myValid; } Suggestions? |