JavaScript - Why Doesn't My For Loop Display The Right Thing To Text Area?
So I am working on a project to take an integer that the user gives, and then get all the squares and cubes of all the numbers before that to the number given. It displays it in a text area. Maybe I am just lost for the moment, but It just prints the number that I give with the square root and cube instead of starting from 1, and ended on the integer I give.
Code: var square_cube = function (){//This f var number = parseInt($("maxbase").value); for (var i=1;i <= number;i++) { var squ = Math.pow(i,2); } var j; for (j=1;j<=number;j++) { var cub = Math.pow(j,3); } var message = i-1 + " " +squ+ " " +cub; $("powers").value = message; } Similar Tutorialshello im attempting to display the output of the radio selection into the textbox. For example, if the user selects 0-15 then display "Your age group is 0-15 years" in the text area. i get the basic logic. i just dont understand how to display the value in the textbox. heres what i have so far if it will clarify my issue. Code: <html> <head> <title>lab 8</title> <script language="javascript"> function textbox() { var i; for(i = 0; i < form1.agegroup.length; i++) { if (form1.agegroup[i].checked) alert("you picked " + form1.agegroup[i].value); } } </script> </head> <body> What is your age group?<br> <form name="form1"> <input type="radio" name="agegroup" value="0-15" checked>0-15<br> <input type="radio" name="agegroup" value="16 to 20">16 to 20<br> <input type="radio" name="agegroup" value="21 to 25">21 to 25<br> <input type="radio" name="agegroup" value="26 to 35">26 to 3<br> <input type="radio" name="agegroup" value="36 and up">36 and up<br> <input type="button" value="submit" onclick="textbox();"> <form name="form2"><textarea rows ="2"> </textarea> </body> </html> btw i know the alert part is wrong. its there because im taking the code i previously had and changing it to display in a textbox instead of an alert. thanks As of right now I have a code that will work in IE but wont work in FireFox...go figure. Basically what I want to have happen is when you type in an area code it will provide an output in a predetermined area of the page. For Example: Input- 512 Output - Austin, TX The code that I have doesn't work with firefox and I was just wondering if there was a code that would allow that to happen. Thanks! Hi, I have a form setup so that selecting a radio button opens a specific text field. The problem is if the user starts to enter information, then switches to a different radio button (perhaps they chose the wrong radio to start), the text they already started to enter on the previous textfield doesn't get cleared. This will be a problem later when inserting to sql. Here is a summary of the code: Code: <head> <script type="text/javascript"> function doClick(objRad){ if (objRad.value=="0"){ document.getElementById("textbox").style.display='block'; } else{ document.getElementById("textbox").style.display='none'; } if (objRad.value=="1"){ document.getElementById("textbox1").style.display='block'; } else{ document.getElementById("textbox1").style.display='none'; } if (objRad.value=="2"){ document.getElementById("textbox2").style.display='block'; } else{ document.getElementById("textbox2").style.display='none'; } } </script> </head> <body> <form action="insert.php" method="post"> <p>Please choose the business type: <input type="radio" name="rad" value="0" onclick="doClick(this)"> Sole Proprietorship <input type="radio" name="rad" value="1" onclick="doClick(this)"> Partnership <input type="radio" name="rad" value="2" onclick="doClick(this)"> Corporation <div id="textbox" style="display:none"> <input type="text" name="txt"> This is my sole proprietorship info.</div> <div id="textbox1" style="display:none"> <input type="text" name="txt"> This is my partnership info.</div> <div id="textbox2" style="display:none"> <input type="text" name="txt">This is my corporation info. </div> </form> </body> Any help is appreciated, Thanks in advance! im clueless when it comes to javascript, but this is what im trying to find: i have a page that has multiple text areas, i also have 4 links that when clicked i want to add some predefined text into the active text area the one with the text cursor in? The Hyperlinks: Code: <a href="#sc">Shift Changed</a> | <a href="#ol">On Leave</a> | <a href="#ot">OverTime</a> | <a href="#ss">ShiftSwap</a> The textareas: PHP Code: <td><textarea name=details$i rows=4 align=absmiddle cols=16 value="$details[$i]\">$details[$i]</textarea></td> as you can see the textareas are created on the fly based on a php array. would anyone be willing to put some code together for this? or even give me the basics on how i can get the active textarea's name so i can pass that to a script that inserts into a given field? I have an image map with 6 areas. Code: <p class="center"><img src="images/car_feature.png" alt="" usemap="#car"/></p> <map id="car" name="car"> <area shape="rect" coords="172,198,195,222" href="#" alt=""/> <area shape="rect" coords="242,79,266,104" href="#" alt=""/> <area shape="rect" coords="293,124,317,149" href="#" alt=""/> <area shape="rect" coords="407,212,431,227" href="#" alt=""/> <area shape="rect" coords="430,300,453,325" href="#" alt=""/> <area shape="rect" coords="565,346,588,370" href="#" alt=""/> </map> I also have 6 DIVs that are hidden and only a single one will appear visible on mouseover of its corresponding image map area. Code: <div id="hidden"> <div class="feature"> Feature 1 </div> <div class="feature"> Feature 2 </div> <div class="feature"> Feature 3 </div> <div class="feature"> Feature 4 </div> <div class="feature"> Feature 5 </div> <div class="feature"> Feature 6 </div> </div> The roadblock I'm running into is the show function in the JavaScript. Code: window.onload = init; function init() { var area = document.getElementById("car").getElementsByTagName("area"); var features = document.getElementById("hidden").getElementsByTagName("div"); hide(); function show() { for(a=0; a < area.length; a++) { if(area[a].onmouseover) { document.getElementById("hidden").getElementsByTagName("div")[a].style.display="block"; } } } function hide() { for(b=0; b < features.length; b++) { document.getElementById("hidden").getElementsByTagName("div")[b].style.display="none"; } } for(i=0; i < area.length; i++) { area[i].onmouseover = show; area[i].onmouseout = hide; } } I'm trying to get it so that if I hover over the first area on the image map, the first hidden DIV will appear, but none of the others. And if I hover over the fourth area, the fourth DIV will appear. I hope this makes sense, and I'd appreciate any and all help towards solving this issue and ending my headache lol Hi, I am wanting to insert text into a text area when a button or link is clicked. I know how to replace the whole lot in the text area, but I want it to insert text where the flashing cursor is in the text box. (Like Wikipedia) If any one can help, Then I will be very, very greatfull. Thank You. hey im new to javascript and im working in this function , i can't get it work here is my code PHP Code: <SCRIPT LANGUAGE="JavaScript"> function text(form1) { var j = document.form1.diary.value; j = j.italics(); document.form1.diary.value = j ; } </SCRIPT> whats the problem ? This is just a goofy little project to add to my learning, but I've come across a problem that would be nice to solve. It is not a TinyMCE or other JS editor replacement, just something to play with for the holidays! In the following program, you can create an HTML template then add/modify common elements and display the results. I can place tags around highlighted areas and insert/append functions where the cursor is positioned. Works OK so far. The problem is when the text exceeds the <textarea> boundaries and I try to tag or insert at cursor, the display reverts to the first line of the <textarea> display. I would like to keep the displayed area within the boundaries and just push down the inserted text. Problem: Is there a simple way to accomplish this task or do I just have to put-up with the bouncy display whenever I insert code into the area? Code: <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <title>Simple JS Editor</title> <!-- One annoyance: When <textarea> content exceeds size of element additional entries cause display to JUMP to beginning of the area being edited. --> <style type="text/css"> .tags { background-Color:lightblue; } .objs { background-Color:pink; } .ctrl { background-Color:lime; } </style> <script type="text/javascript" language="javascript"> <!-- External: src="InsertText.js"></script --> // function insertAtCursor(myField, myValue) { function InsertText(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { // else if (myField.selectionStart != 'undefined') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.selectionStart = startPos + myValue.length; myField.selectionEnd = startPos + myValue.length; } else { myField.value += myValue; } myField.focus(); // new entry here } // calling the function // insertAtCursor(document.formName.fieldName, value); </script> <script type="text/javascript"> <!-- External: src="InsertCode.js"></script --> // Modified from: // http://www.codingforums.com/showthread.php?t=134113 - Author Kor // http://www.codingforums.com/showthread.php?t=182713 var HTMLstart = ['<!DOC HTML>', '<html>','<head>','<title> Untitled </title','', '<style type="text\/css"><\/style>','', '<script type="text\/javascript">', ' function $_(IDS) { return document.getElementById(IDS); }', '<\/script>','', '</head>','<body>','','<h1> Test </h1><hr>','', '</body>','</html>' ]; var RBtnStart = ['<input type="radio" name="RBtn" value="0">RBtn 1', '<input type="radio" id="RBtn" name="RBtn" value="1">RBtn 2', '<input type="radio" id="RBtn" name="RBtn" value="2">RBtn 3','' ]; var CBoxStart = ['<input type="checkbox" id="CBox0" name="CBox0" value="A">CBox A', '<input type="checkbox" id="CBox1" name="CBox1" value="B">CBox B','' ]; var SBoxStart = ['<select id="SBox" name="SBox">',' <option value="">Pick</option>', ' <option value="1">1</option>',' <option value="2">2</option>', ' <option value="3">3</option>',' <option value="4">4</option>', ' <option value="5">5</option>',' <option value="6">6</option>', '</select>','' ]; var TblsStart = ['<table border="1">','<caption> Table </caption', ' <tr>',' <td> 1 </td>',' <td> 2 </td>',' </tr>', ' <tr>',' <td> 3 </td>',' <td> 4 </td>',' </tr>', '</table>','' ]; var ULstart = ['<ul>',' <li> 1 </li>',' <li> 2 </li>',' <li> 3 </li>','</ul>','']; var OLstart = ['<ol>',' <li> A </li>',' <li> B </li>',' <li> C </li>','</ol>','']; var DLstart = ['<dl>',' <dt> A </dt>',' <dt> B </dt>',' <dt> C </dt>','</dl>','']; function formatText(el,tag){ var selectedText = document.selection ?document.selection.createRange().text :el.value.substring(el.selectionStart,el.selectionEnd); // IE:Moz if (selectedText == "") {return false} var newText='<'+tag+'>'+selectedText+'</'+tag+'>'; if(document.selection) { document.selection.createRange().text=newText; } // IE else { // Moz el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length); } } </script> </head> <body> <form name="myForm" onsubmit="return false"> <textarea id="myTextarea" name="myTextarea" rows="18" cols="80" style="font-family: monospace; font-size: 12pt; float: left;"></textarea> <div style="float: left;"><h3 class="tags">Enclose (highlighted)</h3> <input class="tags" value="Bold" onclick="formatText (myTextarea,'b');" type="button"> <input class="tags" value="Italic" onclick="formatText (myTextarea,'i');" type="button"> <input class="tags" value="Underline" onclick="formatText (myTextarea,'u');" type="button"> <br> <input class="tags" value="h1" onclick="formatText (myTextarea,'h1');" type="button"> <input class="tags" value="h2" onclick="formatText (myTextarea,'h2');" type="button"> <input class="tags" value="h3" onclick="formatText (myTextarea,'h3');" type="button"> </div> <div style="float: left;"><h3 class="objs">Insert</h3> <button class="objs" onClick="InsertText(this.form.myTextarea,RBtnStart.join('\n'))">RBtn</button> <button class="objs" onClick="InsertText(this.form.myTextarea,CBoxStart.join('\n'))">CBox</button> <button class="objs" onClick="InsertText(this.form.myTextarea,SBoxStart.join('\n'))">SBox</button> <br> <!-- <button class="objs" onclick="alert('Not coded yet')">1D-Array</button> <button class="objs" onclick="alert('Not coded yet')">2D-Array</button> <button class="objs" onclick="alert('Not coded yet')">Populate</button> <br> <button class="objs" onclick="alert('Not coded yet')">Toggle</button> --> <button class="objs" onClick="InsertText(this.form.myTextarea,TblsStart.join('\n'))">Tabel</button> <button class="objs" onClick="InsertText(this.form.myTextarea,'<br>')">br</button> <button class="objs" onClick="InsertText(this.form.myTextarea,'<p>')">p</button> <br> <button class="objs" onClick="InsertText(this.form.myTextarea,ULstart.join('\n'))">ul-li</button> <button class="objs" onClick="InsertText(this.form.myTextarea,OLstart.join('\n'))">ol-li</button> <button class="objs" onClick="InsertText(this.form.myTextarea,DLstart.join('\n'))">dl-dt</button> </div> <div style="float: left;"><h3 class="ctrl">Control</h3> <button class="ctrl" onclick="document.getElementById('myTextarea').value=HTMLstart.join('\n')">Template</button> <button class="ctrl" onClick="javascript:this.form.myTextarea.focus();this.form.myTextarea.select();"> Highlight Text to Copy</button> <button class="ctrl" onclick="document.getElementById('myTextarea').value=''"> Clear</button> <p> <button class="ctrl" onclick="document.getElementById('myEditResults').innerHTML = document.getElementById('myTextarea').value"> Display</button> </div> <div id="myEditResults" style="float:left; border: 1px solid red; height: 20em; width: 70em; overflow:auto;"> </div> <br style="clear: both;"> </form> </body> </html> So I'm working with a code that I can't seem to get the translation to show up in the text area. The user is supposed to enter text in a text area on the left hand side, hit the translation button, and the translation will appear like a sentence in the right hand text area. I don't seem to be able to get anything to show up in the right hand text area........ I know that i'ts probably something very simple that I am not seeing because at this point I am brain dead. Code: phrases = [["hello","ahoy"],["pardon me","aaarrgghh"],["excuse me","aarrr"], ["hows it going","hows it goin"],["sir","matey"],["madam","proud beauty"], ["woman","beauty"],["children","sprogs"],["where is","whar be"], ["can you help me find","know ye"], ["is that","be that"],["how far is it to?","how many leagues to"], ["the","th'"],["my","me"],["your","yer"],["there","thar"], ["outstanding","outstandin"],["attractive","attractive"],["happy","horny"], ["dead","went t' Davy Jones' locker"],["restroom","head"],["restaurant","galley"], ["hotel","fleabag inn"],["pub","pub"],["I would like to","I be needin' t"], ["I desire","I desire"],["I wish I knew how to","I'm a hankerin' t"], ["my mother told me to","MeAhoy! ol' mum, bless her black soul, always tol' me t"], ["have a great dinner","have a great what crawled out o' t' bung hole"], ["have a cocktail","swill a pint or two o' grog"],["fall on the ground","fall on t' ground"], ["get drunk","get splice t' mainbrace"]]; function Translate(text) { for(var i = 0; i < phrases.length; i++) { var toReplace = new RegExp("\\b"+ phrases[i][0]+"\\b", "i"); var index = text.search(toReplace); while(index != -1) { text = text.replace(toReplace, phrases[i][1]); index = text.search(toReplace); } } return text; } Code: <div> <textarea id="first_text" style="float:left" id="task_list" rows="20" cols="53"></textarea> <button id="translated" width="50px" heigth="100px" ><img src="pirate2.gif" />Translation----></button> <textarea id="second_text" style="float:right" id="task_list" rows="20" cols="53"></textarea> </div> HI to all I am new be and not able to resolve the issue when i tries to edit text area everything works fine for crome and ie but does not work for firefox in fire fox when i try to edit intially everythings works fine but if i click other feild in form and after that try to edit text area backspace key stuck up and does not work please help me ?? code which i am using is menitoned below function stopPropagation(e) { e = e||event; /* get IE event ( not passed ) */ e.stopPropagation? e.stopPropagation() : e.cancelBubble = true; } function checkShortcut(e) { stopPropagation(e); if({8:1,13:1}[e.keycode||e.which]) { if( x ) return true; return false; } } Hi, i want to open a file in a text area, such that the user can either browse for a file and when selected it will open in a text box on the page, or the user can select a file from a list of active links on the page and this will open in the text area. I am new to java and dont know where to start on this, i have been browsing resources on the internet but have not found anything to get me started, would anybody be able to help? Thanks Hi, I have a text area that I want to add simple html formatting buttons to. The user should be able to: - highlight text and click a 'bold' button - highlight text and click 'itallic' button - Add bulleted list - Link I've looked at a number of WYSIWYG javascript examples, but they seem to accept Microsoft Word formatting, which I dont want. I'll admit I'm new to javascript, so my apologies if this looks like crap. Code: Taken out due to fix I'm trying to get this javascript to return a level to this form field. Code: taken out, due to fix Need help with my text box. I want to make it so if i have several text boxes only one number can be entered once. So if i type the number 15 in the first text box and type 15 in the second text box an error will occur saying you cant enter the same number twice. Any idea how to do this? Code: <html> <head> <title>Untitled Document</title> <script> function checkForInvalid(obj) { obj.value = obj.value.replace(/[^0-9\-]|(-{2,})/gi, (RegExp.$1.indexOf("-") > -1) ? "-" : ""); } </script> </head> <body> <form name="myForm"> <input type="text" name="one" onkeyup="checkForInvalid(this)"> <br> <input type="text" name="two" onkeyup="checkForInvalid(this)"> <br> <input type="text" name="three" onkeyup="checkForInvalid(this)"> </form> </body> </html> Thanks I have a need to display, edit and save the contents of a text area to a text file or what ever is best suited, directly to the website root or folder within the root of the site. Is there anyway this can be done with out database software? As I dont have the option to install mysql or any other software to the webserver. Any help would be greatly appreciated. Thx Just a little backround: The webserver is acually an open source linux firewall which i was able to edit the apache config file to host a second site. I just want the ability to store edit and display some network information within a very small site I made without the use of a database. Is this even possible? Hello im trying to update a text area value with edited code with javascript, i dont know how to and im asking if you guys know
Hi, I'm a student learning web design and having a problem with some javascript code, I'm validating a text area, i dont have a problem limiting how many characters can be typed in the textarea, but I cant get it to give an error if there is no text in the text area. In the code below the validateMes() function is not working, the other functions work fine Javascript code: Code: function validateLimit(fld){ var error =""; if(fld.value.length > 300){ error = "Cannot exceed 300 characters.\n" fld.style.background = 'Yellow'; }else{ fld.style.background = 'White'; } return error; } function validateMes(fld) { //this function not working var error = ""; if (fld.value.length == 0) { fld.style.background = 'Yellow'; error = "The Message field has not been filled in.\n" } else { fld.style.background = 'White'; } return error; } function validateFormOnSubmit(form1) { //master validating function var reason = ""; reason += validateLimit(form1.mess); reason += validateMes(form1.mess); if (reason != "") { alert("Some fields need correction:\n" + reason); return false; }else{ alert("Message has been submitted"); return true; } } Html form code: Code: <form name="form1" id="form1" onsubmit="return validateFormOnSubmit(this)" > <div class="box"> <h1>CONTACT FORM :</h1> <label> <span>Full name</span> <input type="text" class="input_text" name="name" id="name" value=""/> </label> <label> <span>Email</span> <input type="text" class="input_text" name="emailbox" id="emailbox" value=""/> </label> <label> <span>Subject</span> <input type="text" class="input_text" name="subject" id="subject" value=""/> </label> <label> <span>Message</span> <textarea class="message" name="mess" id="mess" ></textarea> <span>*Message limited to 300 characters</span> <input type="submit" class="button" value="Submit Form" /> </label> </div> </form> I can't see what I'm doing wrong, would really appreciate some help Thanks Hi all ! I have written code for select options one. In that option one of the option is to select others. When i select others automatically the cursor should goto others text area box. Any suggessions please. 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>Smartcard Gen2</title> <link rel="stylesheet" type="text/css" href="style.css"/> <script type="text/javascript" charset="utf-8"> var notEmpty=function(){ document.write("Problem Submitted, Thank You"); window.open(list.html); } </script> </head> </head> <body> <div class="container">, <div class="topbar"> <p>Report a Problem<a href="list.html" class="button back black"><span></span> ATM Details</a></p> </div> <div class="content"> <h6>Find ATMs by Address:</h6> <div class="box"> <table width="95%" border="0" align="center" cellpadding="8" cellspacing="0"> <tr> <td width="33%" align="right" valign="middle"><strong>Problem :</strong></td> <td> <FORM ACTION="#" NAME=latin> <SELECT NAME="words" > <option value="ATM NOT PRESENT">ATM not present</option> <option value="ATM IS BROKEN">ATM Broken</option> <option value="MASTERCARD IS NOT ACCEPTED">ATM doesnot accept MasterCard</option> <option value="ATM IS NOT ACCESSIBLE">ATM is not accessible</option> <option value="others" id="others">Others</option> </select> </FORM> </td> </td> </tr> </table> <div class="box"> <table width="95%" border="0" align="center" cellpadding="8" cellspacing="0"> <tr> <td width="33%" align="right" valign="middle"><strong>Other :</strong></td> <td width="67%" align="left" valign="top"><input name="textfield3" type="textarea" rows="25" coloumns="15" id="textfield3" placeholder=" " /></td> </tr> </table> </div> <a href="#" class="transactions" onclick="notEmpty();">Submit</a></div> </div> </body> </html> Hello, I've been looking around the web for a simple JavaScript to solve this problem but can't seem to find something that would work both in IE and FF and the other major browsers? So basically I have a page listing about a dozen badges people can use to link back to me. I have presented the code for each badge (eg. a href, img src, alt...) in a separate textarea and I'd really love to add a link next to each textarea that would say something like "Click here to copy to Clipboard" then it would copy the text from within the corresponding textarea to the Clipboard so as to eliminate the need for Ctrl+A, Ctrl+C. Thank you in advance people! |