JavaScript - Problem With Displaying A Count
Hello all i'm stuck on the last part of my program. Basically it will generate the score and players position but it will no show the following:
I'm also having trouble stopping the loop from going over 80 Now add code to your program which will: ! declare and initialise a variable to keep count of how many goes the player takes to get out; ! add one to this count every time the loop is repeated; ! write out the count in a suitable message at the end. Any help is very much appreciated. [CODE] var countMoves = 0; while (playersPosition <80) { playersScore = rollDie(); document.write('Sco ' + playersScore); playersPosition = playersScore + playersPosition; document.write(' squa ' + playersPosition); indexOfNumber = findIndexOf(playersPosition, specialSquaresArray); if (indexOfNumber != -1) { document.write(' ladder to square ' + connectedSquaresArray[indexOfNumber]); document.write('<BR>'); document.write('Sco ' + playersScore); playersScore = connectedSquaresArray[indexOfNumber] + playersScore; document.write(' squa ' + playersScore); playersPosition = playersScore; } document.write('<BR>'); } for (count =1; count <=array.length; count = count + 1) if(array[count] > array[countMoves]) { countMoves = count; } document.write('it took ' + indexOfNumber + 'goes to get out'); [CODE] Similar TutorialsHi all, I have a code that will fetch out the data from database OnMouseOver. But it is working fine if don't add table on the div which will come OnMouseOver. If i try to show the fetched data in table then the code doesn't work. Please someone help me with this. Here is my code: Code: <script type="text/javascript" language="JavaScript"> var cX = 0; var cY = 0; var rX = 0; var rY = 0; function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;} function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;} if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; } else { document.onmousemove = UpdateCursorPosition; } function AssignPosition(d) { if(self.pageYOffset) { rX = self.pageXOffset; rY = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop) { rX = document.documentElement.scrollLeft; rY = document.documentElement.scrollTop; } else if (document.body) { rX = document.body.scrollLeft; rY = document.body.scrollTop; } if(document.all) { cX += rX; cY += rY; } d.style.left = (cX+10) + "px"; d.style.top = (cY+10) + "px"; } function HideContent(d) { if(d.length < 1) { return; } document.getElementById(d).style.display = "none"; } function ShowContent(d) { if(d.length < 1) { return; } var dd = document.getElementById(d); AssignPosition(dd); dd.style.display = "block"; } function ReverseContentDisplay(d) { if(d.length < 1) { return; } var dd = document.getElementById(d); AssignPosition(dd); if(dd.style.display == "none") { dd.style.display = "block"; } else { dd.style.display = "none"; } } //--> </script> </head> <body> <table align="center" width="300px"/> <tr> <td>MakeID</td> <td>Make</td> <td>Veh Type</td> </tr> <?php $conn = mysql_connect ('localhost', 'root', ''); mysql_select_db ('my_db', $conn); function create_div($width, $height, $fields, $table, $w_field, $w_value, $unique) { $f = implode("`, `", $fields); $sql = "SELECT `$f` FROM `$table` WHERE `$w_field` = '$w_value'"; $res = mysql_query($sql) or die(mysql_error()); $div = "<div align=center id=\"data".$unique."\" style=\"display:none; position:absolute; border-style:solid; background-color:white; padding: 10px; width:".$width."px; height:".$height."px\" />\n"; $div .= '<table width="100%" cellpadding="4" cellspacing="2">'; $div .= '<tr><th>Serial</th><th>First Name</th><th>Email</th></tr>'; while($r = mysql_fetch_assoc($res)){ $div .= '<tr>'; $div .= '<td>'.$r['id'].'</td>'; $div .= '<td>'.$r['firstname'].'</td>'; $div .= '<td>'.$r['email'].'</td>'; $div .= "</tr>"; $div .= "</table>"; $div .= "</div>\n"; return $div; } $sql = "SELECT * FROM name"; $res = mysql_query($sql) or die(mysql_error()); $i=0; $fields = array("id", "firstname", "email"); while($r = mysql_fetch_assoc($res)){ echo create_div("300", "200", $fields, "admin", "id", $r['id'], $i); ?> <tr> <td><?php echo $r['id']; ?></td> <td><a onmouseover="ShowContent('data<?php echo $i; ?>'); return true;" onmouseout="HideContent('data<?php echo $i; ?>'); return true;" href="#"><?php echo $r['name'];?></a> </td> <td><?php echo $r['desc']; ?></td> </tr> <?php $i++; } ?> </table> </body> </html> /** The <a> is a list of menu items that when clicked.... a specific gallery-slider-images should been shown in relation to the galleryId....<div class"gallery" is hidden in CSS> I'd like to use jQuery to complete this task if at all possible, I know it's prob SIMPLE to U GURU's but being new i can't seem to .show() the selected 'gallery' w/o showing them all........... BEST REGARDS _ STH <div id="gallery-menu"> <?php foreach ($galleries as $gallery) : ?> <a onclick="showGallery(<?= $gallery['gallery']['id'] ?>); return false;"><?= $gallery['gallery']['name'] ?> <?php endforeach ?> </div> <?php foreach ($galleries as $gallery): ?> <div id="<?= $gallery['gallery']['id'] ?>" class="gallery"> <div class="slider" style="width; 100%; height: 100%;"> <ul> <?php foreach ($gallery['images'] as $image): ?> <li class="galleries-container"> <img src="<?= UCMVC_APP_BASE_URL ?>/gallery/retrieve-image/<?= $image['id'] ?>" alt="<?= $image['name'] ?>" title="<?= $image['name'] ?>" /> </li> <?php endforeach; ?> </ul> </div> </div> <?php endforeach; ?> // javascript // function showGallery(galleryId) { ????!?!?!?!?! } Ahoy, Lemme try to explain this as best as I can. Bullet points might help: When someone clicks on an image here (http://gta.kwivia.co.uk/gta-iv/), the rest of the images collapse and become invisible Below the image, some links appear Also, there will be a "show other images" button which will then show the rest of the images http://gta.kwivia.co.uk/gta-iv/ I will appreciate all solutions to this problem. If you need to know anything, simply ask me. Hi, I am not a Javascript programmer and I am facing some barriers. Maybe some of you could help me. I would need a script that can be used to count down until any given date with hour, minutes and seconds. For example: Quote: September 10, 2009 16:02:00 Bob Kuspe I've been looking everywhere for a script that counts up from 1 to 10, but can't find anything. I even searched the forums. Basically just something that starts from 1 and then replaces itself with 2, and so on. Thanks! Deleted
Hi, I want to do a redirect count so that the user can see the count going down. for example, I want them to be able to see the following. You will be redirected in 5 seconds. The user should be able to see the count going down from 5 to 4 to 3 to 2 to 1 and then they are redirected. I can get the page to redirect after 5 seconds but I want the user to be able to see it count down. Thanks in advance for your help hi i am new to javascript. i make a mcq quiz website in one of server side script. now for that website i want to make count down timer so when that quiz starts the user will have 5 minutes to complete that quiz if use does not able to complete quiz in given time then quiz should disable and shows the user score how can i achieve this I would like to count how many duplicate values I have in an array. My below attempt doesnt count the duplicate values: Code: var ct = 0; for(var i = 0;i < myArray.length;i++) { var myData = getData[i].city; if(myData == myData) { ct++; } alert("Total Count = " + ct); } Please advise the best way to do this. Hee guys, I've got a little bit of a problem on my hand. Someone has asked me to help them on a FREE forum host. You have no access to PHP or SQL or anything like that. Just the templates, but even those are really messy! Now on the navagation bar there a PM section (obviously) but the wording they have used is very long and ugly. I was wondering if it would be possible to change the wording whilst still having it show the amount of PM's that you have. If you need anymore information just ask, but I really hope someone can help Hello, I have this script (which i didn't program) which is suppose to count down an amount of time, and then redirect the page to another place. It works fine on IE/Opera but it doesn't on Netscape/Mozilla. I was wondering if any one could tell me the couse or another script that will work on most browsers. Thanks a lot Code: time_in_sec = 300; function nextSec() { m = Math.floor(time_in_sec / 60); s = time_in_sec % 60; if (s < 10) { s = "0" + s; } if ((m == 0)&&(s == 0)) { location.replace("SOME_URL"); } else { document.all.counter.innerHTML = '<font style="font-size: 13pt" color="#999999">' + m + ":" + s + "</font>"; window.setTimeout('nextSec()',1000); } time_in_sec--; } Hi All, Not sure if you can help, I'm having some issues with a count down timer that outputs a time until deadline. It was all working fine however since the clocks have gone back in the UK it is a hour out. However I was under the impression that the UTCHours called GMT time with the clocks going forward & backwards. - if this is not the case how do I call the correct GMT time or the server time? The server time is correct however the script displays the wrong message. Here is the script: [JavaScript] var lastimage = ""; function checkTimer() { function b(a, b, c) { - Pastebin.com Thanks! I'm trying to make a countdown timer, it works fine if I define the value myself from where it has to start. However, when I try to take output from the user it says undefined and 'Nan'. Here is the code of html Code: <html> <head> <script type="text/javascript" src = "experimento2.js"></script> <link rel="stylesheet" type="text/css" href="experimento2.css" /> </head> <body> <h1> Count DOWn!</h1> Enter the number to begin countdown with : <input type = "text" id = "user" onchange = "input()"/> <input type="button" onclick = "timedCount()" value = "begin" id = "begin" /> <input type = "button" onclick="stopCount()" value = "stop" id = "end" /><br> <div id = "start" >00 </div> </body> </html> Here is the script: Code: var t; var l =document.getElementById("user").value; var c = l; function timedCount() { document.getElementById('start').innerHTML=c; c=c-1; t=setTimeout("timedCount()",1000); } function stopCount() { clearTimeout(t); } Basically my problem is that if I give c a value like c = 30. it works fine. But when I try to take the input , it gives an undefined error. I'm trying to make a count-up timer that counts to 100 or 1000 then adds 1 to another number. i would like the timer speed to be adjustable if possible...i'm kinda new to javascript so any help with this would be appreciated. Hi all i have a question... In my below code, I need to get rid of the radio option in my file. Count pure words and Count everything as words Also if i specify some content in the input box, it shows all the word count in the output box. I need only few mentioned words to be dispalyed instead For example, if i give input as below in the input box "Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and in view images in 3D, just to name a few. It's also integral to the intranet applications and and other e-business solutions that are the foundation of corporate computing." I need only to display the count of Java , yours , in , and so that i output will be Java - 1 yours - 0 in - 2 and - 3 Can someone help me out in this please... Thanks a lot!!!:) Html Code ======================================================= Code: <html> <head> <title> Word Count </title> <script language = "JavaScript"> function process1 (count) { // for words m=new Array(10000); m1=new Array(10000); N=new Array (10000); for (i=0;i<=1;i++) // which is chosen { if (count=1) { ch=i; } } A=count.message.value; // original message B=""; A=" " + A+" "; A=A.toUpperCase(); // changes all alphas to Upper case if (ch==0) // get rid of everything but apha's { condense1(count); } else { lesscondense(count); } for (i=1;i<=A.length;i++) // trims leading spaces and multiple spaces { if ((!(A.charAt(i)==" ")) || (!(A.charAt(i-1)==" "))) {B=B + A.charAt(i); } } //count.result1.value=B; B=B+" "; // makes sure there is a space at end k=0; str=" "; for (i=0;i<=B.length;i++) { k1=B.indexOf(str,k); if (k1==-1) //end of string B { Numwords=i-1; break; } m[i+1]=B.substring(k,k1); // places all the words into an array m k=k1+1; } //count.result1.value=B; C=""; NN=0; for (i=1;i<=Numwords; i++) // Numwords is total number of words { if (!(m[i]=="")) // only looks at m1 words that have not been processed before (not empty) { NN=NN+1; //unique word stored in m1 array m1[NN]=m[i]; N[NN]=1; // initialize counter for word for (j=i+1;j<=Numwords+1;j++) //counts and makes m1 elements with unique word empty. { if (m1[NN]==m[j]) { N[NN]=N[NN]+1; m[j]=""; } } } } C=C+"Unique:" + NN+" Total:" + Numwords+"\n"; C=C+"Freq.\tWord\n"; for (i=1;i<=NN;i++) // sets up C for showing { C=C + N[i]+ "\t" + m1[i] + "\n"; } count.result1.value=C; } function condense1(count) { // allows only alpha's and spaces for choice 1 C=""; for (i=0;i<=A.length-1;i++) { k=A.charCodeAt(i); if (((k>64) && (k<91)) || (k==32)) { C=C+A.charAt(i); } else { C=C+" "; } } A=C; //count.result1.value=B; } function lesscondense(count) { // allows all characters from space on C=""; for (i=0;i<=A.length-1;i++) { k=A.charCodeAt(i); if (k>31) { C=C+A.charAt(i); } else { C=C+" "; } } A=C; } //======================================== function letters1(count) { // counting characters upto unicode #255 mN=new Array(5000); for (i=0;i<=1;i++) // which is chosen { if ( count.radio2[i].checked) { ch1=i; } } A=count.message.value; T=0; for (i=0;i<=5000;i++) // initialize Array mN to 0 { mN[i]=0; } for (i=0;i<=A.length-1;i++) // k is character and counted in mN[k] { k=A.charCodeAt(i); mN[k]=mN[k]+1; } //count.result1.value=E; D=""; D=D+"Freq.\tLetter\n" if (ch1==0) // shows only alpha's and total number of letters T { for (i=65; i<91;i++) { if (!(mN[i]==0)) { D=D + mN[i] + "\t"+ String.fromCharCode(i) + "\n"; T=T+mN[i]; } } for (i=97;i<=122;i++) { if (!(mN[i]==0)) { D=D+mN[i]+"\t"+String.fromCharCode(i)+"\n"; T=T+mN[i]; } } } else // shows all characters from space (32) to unicode 255 { for (i=32; i<=255;i++) { if (!(mN[i]==0)) { D=D + mN[i] + "\t"+ String.fromCharCode(i) + "\n"; T=T+mN[i]; } } } count.result1.value=D; count.total.value=T; count.wordav.value=Math.round(T/Numwords*10000)/10000; // rounds off } //-- End </script> </head> <body> <form name ="count"><a name="Word_Counter"></a><font size="+1"><p> Count pure words<input type="radio" name="radio1" value="1" CHECKED> Count everything as words <input type ="radio" name="radio1" value="0"><br> <br> <table border="0" cellPadding="1" cellSpacing="1"> <tr> <td><input id="button1" name="button1" onclick="process1(document.count)" style="height: 24px; width: 165px; font-weight: bold" type="button" value="COUNT WORDS"></td> <strong><font face="Arial" color="#000080">Input your text into the box below:</font></strong><br><textarea cols=33 name=message rows=12 style="background-color: #ffffff; font-size: 10pt" wrap=PHYSICAL></textarea> <textarea cols=33 name=result1 rows=12 style="font-size: 10pt; font-family: Arial" wrap=PHYSICAL>WORD COUNT OUTPUT BOX</textarea> <br><table border=0 cellPadding=1 cellSpacing=1> <input type="reset" value="Reset" name="B1"> </body> </html> ======================================================= I've downloaded a simple wysiwyg script from the internet, however I want to add a wordcounter to it. The main idea is that the amount of words is refreshed every time a new character is entered. However I haven't got a clue on how to implement this, I've used javascript a lot a few years ago.. but this is out of my league. So I'm hoping someone can help me with this. The html file: Quote: <html> <head> <style type="text/css">@import url('SimpleTextEditor.css');</style> <script src="SimpleTextEditor.js"></script> <script type="text/javascript"> function countWords(){ document.form1.wordcount.value = document.form1.inputString.value.split(' ').length + '/300 words'; if (document.form1.inputString.value.split(' ').length >= 50){ document.getElementById("wordcount").style.color = "red"; }else{ document.getElementById("wordcount").style.color = "black"; } } </script> </head> <body> <form name="form1" method="post"> <div style="height:34px;width:750px;margin-bottom:5px;background-image:url('mainbar.png');background-repeat:no-repeat; "><input style="margin-top:6px;margin-left:25px;" name="wordcount" type="text" value="" size="6"></div> <textarea name="inputString" id="inputString" cols="70" rows="4" onkeyup='countWords();'></textarea> <br> <script> var ste = new SimpleTextEditor("inputString", "ste"); ste.cssFile = 'test.css'; ste.charset = 'iso-8859-1'; ste.init(); </script> <input type="submit" value="submit" onclick="ste.submit();"> </form> </body> </html> The javascript file: Quote: function SimpleTextEditor(id, objectId) { if (!id || !objectId) { alert("SimpleTextEditor.constructor(id, objectId) failed, two arguments are required"); } var self = this; this.id = id; this.objectId = objectId; this.frame; this.viewSource = false; this.path = ""; // with slash at the end this.cssFile = ""; this.charset = "iso-8859-1"; this.editorHtml = ""; this.frameHtml = ""; this.textareaValue = ""; this.browser = { "ie": Boolean(document.body.currentStyle), "gecko" : (navigator.userAgent.toLowerCase().indexOf("gecko") != -1) }; this.init = function() { if (document.getElementById && document.createElement && document.designMode && (this.browser.ie || this.browser.gecko)) { // EDITOR if (!document.getElementById(this.id)) { alert("SimpleTextEditor "+this.objectId+".init() failed, element '"+this.id+"' does not exist"); return; } this.textareaValue = document.getElementById(this.id).value; var ste = document.createElement("div"); document.getElementById(this.id).parentNode.replaceChild(ste, document.getElementById(this.id)); ste.id = this.id+"-ste"; ste.innerHTML = this.editorHtml ? this.editorHtml : this.getEditorHtml(); // BUTTONS var buttons = ste.getElementsByTagName("td"); for (var i = 0; i < buttons.length; ++i) { if (buttons[i].className == "button") { buttons[i].id = this.id+'-button-'+i; buttons[i].onmouseover = function() { this.className = "button-hover"; } buttons[i].onmouseout = function() { this.className = this.className.replace(/button-hover(\s)?/, "button"); } buttons[i].onclick = function(id) { return function() { this.className = "button-hover button-click"; setTimeout(function(){ document.getElementById(id).className = document.getElementById(id).className.replace(/(\s)?button-click/, ""); }, 100); } }(buttons[i].id); } } // FRAME if (this.browser.ie) { this.frame = frames[this.id+"-frame"]; } else if (this.browser.gecko) { this.frame = document.getElementById(this.id+"-frame").contentWindow; } this.frame.document.designMode = "on"; this.frame.document.open(); this.frame.document.write(this.frameHtml ? this.frameHtml : this.getFrameHtml()); this.frame.document.close(); insertHtmlFromTextarea(); } }; function lockUrls(s) { if (self.browser.gecko) { return s; } return s.replace(/href=["']([^"']*)["']/g, 'href="simpletexteditor://simpletexteditor/$1"'); } function unlockUrls(s) { if (self.browser.gecko) { return s; } return s.replace(/href=["']simpletexteditor:\/\/simpletexteditor\/([^"']*)["']/g, 'href="$1"'); } function insertHtmlFromTextarea() { try { self.frame.document.body.innerHTML = lockUrls(self.textareaValue); } catch (e) { setTimeout(insertHtmlFromTextarea, 10); } } this.getEditorHtml = function() { var html = ""; html += '<input type="hidden" id="'+this.id+'" name="'+this.id+'" value="">'; html += '<table class="ste" cellspacing="0" cellpadding="0">'; html += '<tr><td class="bar"><table id="'+this.id+'-buttons" cellspacing="0" cellpadding="0"><tr>'; //html += '<td><select onchange="'+this.objectId+'.execCommand(\'formatblock\', this.value);this.selectedIndex=0;"><option value=""></option><option value="<h1>">Heading 1</option><option value="<h2>">Heading 2</option><option value="<h3>">Heading 3</option><option value="<p>">Paragraph</option><option value="<pre>">Preformatted</option></select></td>'; //html += '<td><div class="separator"></div></td>'; html += '<td class="button"><img src="'+this.path+'images/bold.gif" width="20" height="20" alt="Bold" title="Bold" onclick="'+this.objectId+'.execCommand(\'bold\')"></td>'; html += '<td class="button"><img src="'+this.path+'images/italic.gif" width="20" height="20" alt="Italic" title="Italic" onclick="'+this.objectId+'.execCommand(\'italic\')"></td>'; html += '<td class="button"><img src="'+this.path+'images/underline.gif" width="20" height="20" alt="Underline" title="Underline" onclick="'+this.objectId+'.execCommand(\'underline\')"></td>'; html += '<td><div class="separator"></div></td>'; html += '<td class="button"><img src="'+this.path+'images/left.gif" width="20" height="20" alt="Align Left" title="Align Left" onclick="'+this.objectId+'.execCommand(\'justifyleft\')"></td>'; html += '<td class="button"><img src="'+this.path+'images/center.gif" width="20" height="20" alt="Center" title="Center" onclick="'+this.objectId+'.execCommand(\'justifycenter\')"></td>'; html += '<td class="button"><img src="'+this.path+'images/right.gif" width="20" height="20" alt="Align Right" title="Align Right" onclick="'+this.objectId+'.execCommand(\'justifyright\')"></td>'; html += '<td><div class="separator"></div></td>'; html += '<td class="button"><img src="'+this.path+'images/ol.gif" width="20" height="20" alt="Ordered List" title="Ordered List" onclick="'+this.objectId+'.execCommand(\'insertorderedlist\')"></td>'; html += '<td class="button"><img src="'+this.path+'images/ul.gif" width="20" height="20" alt="Unordered List" title="Unordered List" onclick="'+this.objectId+'.execCommand(\'insertunorderedlist\')"></td>'; html += '<td><div class="separator"></div></td>'; html += '<td class="button"><img src="'+this.path+'images/outdent.gif" width="20" height="20" alt="Outdent" title="Outdent" onclick="'+this.objectId+'.execCommand(\'outdent\')"></td>'; html += '<td class="button"><img src="'+this.path+'images/indent.gif" width="20" height="20" alt="Indent" title="Indent" onclick="'+this.objectId+'.execCommand(\'indent\')"></td>'; //html += '<td><div class="separator"></div></td>'; //html += '<td class="button"><img src="'+this.path+'images/link.gif" width="20" height="20" alt="Insert Link" title="Insert Link" onclick="'+this.objectId+'.execCommand(\'createlink\')"></td>'; //html += '<td class="button"><img src="'+this.path+'images/image.gif" width="20" height="20" alt="Insert Image" title="Insert Image" onclick="'+this.objectId+'.execCommand(\'insertimage\')"></td>'; //html += '<td><div class="separator"></div></td>'; //html += '<td class="button"><img src="'+this.path+'images/help.gif" width="20" height="20" alt="Help" title="Help" onclick="'+this.objectId+'.openWindow(\''+this.path+'help.html\', \'300\', \'300\')"></td>'; html += '</tr></table></td></tr>'; html += '<tr><td class="frame"><iframe id="'+this.id+'-frame" frameborder="0"></iframe></td></tr>'; html += '<tr><td class="source"><input id="'+this.id+'-viewSource" type="checkbox" onclick="'+this.objectId+'.toggleSource()"> View Source</td></tr>'; html += '</table>'; return html; }; this.getFrameHtml = function() { var html = ""; html += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; html += '<html><head>'; html += '<meta http-equiv="Content-Type" content="text/html; charset='+this.charset+'">'; html += '<title>SimpleTextEditor frame</title>'; html += '<style type="text/css">pre { background-color: #eeeeee; padding: 0.75em 1.5em; border: 1px solid #dddddd; }</style>'; if (this.cssFile) { html += '<link rel="stylesheet" type="text/css" href="'+this.cssFile+'">'; } html += '<style type="text/css">html,body { cursor: text; } body { margin: 0.5em; padding: 0; }</style>'; html += '</head><body></body></html>'; return html; }; this.openWindow = function(url, width, height) { var x = (screen.width/2-width/2); var y = (screen.height/2-height/2); window.open(url, "", "scrollbars=yes,width="+width+",height="+height+",screenX="+(x)+",screenY="+y+",left="+x+",top=" +y); }; this.toggleSource = function() { var html, text; if (this.browser.ie) { if (!this.viewSource) { html = this.frame.document.body.innerHTML; this.frame.document.body.innerText = unlockUrls(html); document.getElementById(this.id+"-buttons").style.visibility = "hidden"; this.viewSource = true; } else { text = this.frame.document.body.innerText; this.frame.document.body.innerHTML = lockUrls(text); document.getElementById(this.id+"-buttons").style.visibility = "visible"; this.viewSource = false; } } else if (this.browser.gecko) { if (!this.viewSource) { html = document.createTextNode(this.frame.document.body.innerHTML); this.frame.document.body.innerHTML = ""; this.frame.document.body.appendChild(html); document.getElementById(this.id+"-buttons").style.visibility = "hidden"; this.viewSource = true; } else { html = this.frame.document.body.ownerDocument.createRange(); html.selectNodeContents(this.frame.document.body); this.frame.document.body.innerHTML = html.toString(); document.getElementById(this.id+"-buttons").style.visibility = "visible"; this.viewSource = false; } } document.getElementById(this.id+"-viewSource").checked = this.viewSource ? "checked" : ""; document.getElementById(this.id+"-viewSource").blur(); }; this.execCommand = function(cmd, value) { if (cmd == "createlink" && !value) { var url = prompt("Enter URL:", ""); if (url) { this.frame.focus(); this.frame.document.execCommand("unlink", false, null); if (this.browser.ie) this.frame.document.execCommand(cmd, false, "simpletexteditor://simpletexteditor/"+url); else if (this.browser.gecko) this.frame.document.execCommand(cmd, false, url); this.frame.focus(); } } else if (cmd == "insertimage" && !value) { var imageUrl = prompt("Enter Image URL:", ""); if (imageUrl) { this.frame.focus(); this.frame.document.execCommand(cmd, false, imageUrl); this.frame.focus(); } } else { this.frame.focus(); this.frame.document.execCommand(cmd, false, value); this.frame.focus(); } }; this.isOn = function() { return Boolean(this.frame); }; this.getContent = function() { try { return unlockUrls(this.frame.document.body.innerHTML); } catch(e) { alert("SimpleTextEditor "+this.objectId+".getContent() failed"); } }; this.submit = function() { if (this.isOn()) { if (this.viewSource) { this.toggleSource(); } document.getElementById(this.id).value = this.getContent(); } }; } As you can see there are a few lines I wrote myself in the HTML file, but they didn't do the trick. How can to obtain length of string variable, for example if I have: var msg = 'hello world!'; Does it exist a method to count string characters? Hey Guys, I am stuck on something that is probably a straight forward issue. Just can't get my head around it. Basically I have a whole bunch of checkboxes and I want to count the number that have the same class (only when selected) Example: Code: <input type="checkbox" name="Paris" value="FR" /> <input type="checkbox" name="Marseille" value="FR" /> <input type="checkbox" name="Cardiff" value="UK" /> <input type="checkbox" name="London" value="UK" /> <input type="checkbox" name="ROME" value="IT" /> When user checks a checkbox, output the number of checked boxes that have the same value. My thoughts: Code: $("input[type="checkbox"]").click(function(event){ alert($('input[type="checkbox"]:checked').val($('input[type="checkbox"]:checked').val()).length); }); Not sure what the correct logic should be. Anyone with any ideas? |