JavaScript - Textarea Javascript Problems
Similar TutorialsHi, I am having trouble searching for text in a textarea in all browsers. I display formatted text in a textarea with tinyMCE editor. Some of the text contains blanks ('______') which the user needs to find and fill in (usually with a number). I have written a new button on the toolbar of the editor which will find and highlight the blank when clicked. The user will click the button, fill in the text, click the button, fill in the text, etc. In IE the blanks are highlighted just fine. The only problem is: user clicks button and first blank is highlighted. User fills in the text then clicks the button again. Second blank should be highlighted but it skips right to the third blank. If you don't fill anything in, the next blank will be highlighted. If you highlight and then fill anything in, the next blank is skipped and the following blank is highlighted. Any thoughts? But my worst problem is with Mozilla. I get an error. It does not act like setSelectionRange(pos, pos+len(str)) is a valid function call. I receive the following error: "component returned failure code: 0x800004005 (NS_ERROR_FAILURE)[nsIDOMNSHTML TextareElement.setSelectionRange]" Here is my function: var win = window; var n = 0; var str = '______'; function FindBlanks() { var txt, i, found; win = tinyMCE.get('txtPolicy').getDoc(); if (str == "") return false; if (window.execScript) { txt = win.body.createTextRange(); //Find the nth match from the top of the page for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } // If found, mark it and scroll it into view if (found) { txt.moveStart("character", -1); txt.findText(str); txt.select(); txt.scrollIntoView(); // n = i--; n++; } //Otherwise, start over at the top of the page and find first match else { if (n > 0) { n = 0; alert("End of document has been reached."); } //Not found anywhere, give message. else alert("No blanks found."); } } else { //document.getElementById('txtPolicy').setFocus; var ht = '______'; if (ht.length == 0) { alert('highlightText has zero lenth'); return false; } var str2 = document.getElementById('txtPolicy').value; var startPos = str2.indexOf(ht); if (startPos == -1) { alert('No blanks found'); return false; } document.getElementById('txtPolicy').focus(); document.getElementById('txtPolicy').setSelectionRange(startPos, startPos + ht.length); return true; if (n == 0) alert ("No blanks found."); } return false; } Can anyone help me with this? Thanks. Hi, I am just a noob and this is my first go at javascript and html I am trying to figure out how to display info from an array in the <textarea>, I have tried a number of things nothings worked and I know it must be something simply but have tried a number of things I also have to clear the <textarea> after it displays the info mentioned above and I think I have that sorted but I also have to have the <textarea> display all signup info stored in the array when a user clicks on a button Here's the code Code: function show() { var myArray = new Array(); myArray[0] = document.getElementById('fullname').value; myArray[1] = document.getElementById('Address').value; myArray[2] = document.getElementById('Phone').value; document.writeln('Thank you for signingup,' + ' ' + myArray[0] + '. Your details will be confirmed by E-mail to ' + myArray[2] ); document.writeln("<br>") document.writeln('Details:') document.writeln("<br>") for (var i=0; i<myArray.length; i++) {document.write(myArray[i] + "<br />"); } } Thanks hi i am new to javascript. i want to make a form where a textarea, some buttons like bold,italic,link etc will be availablw. when user selecet some text from textarea and click bold button then one openig and closing tag will be added like this [sb]abc[/sb] how can i do this using javascript. any idea? pls. help I'm not 100% sure if this can be done (I haven't been particularly successful in my Google searches). I'm using Javascript and forms to create conditional information randomizers for data. An example might be "What should you have to eat?" The person can generate a random result or select restrictions (selecting an allergy to X would eliminate X-related results). I prefer to work with black backgrounds. Even if I end up changing a default site layout to non-black (for audience purposes), I'd want a personalized CSS for myself. I'm running into some difficulty determining how to make my textarea black. Is there a way to apply CSS to textarea boxes (including those related to javascript?) Ideally, I'd like to be able to automatically style every textarea but if that is not possible in relation to javascript, I'd settle for changing the code for individual boxes. I was unsure where to place this topic so feel free to move it if it's better suited for CSS. Thanks *** I figured I didn't need to bump my post needlessly, but Thanks to "devnull69" as the provided solution worked. For some reason, I was confused about how to type that operation in css properly. That's probably one of the problems that arises when one combines staying up late with learning multiple programming languages at the same time. All is well now. I found and am using the following script to add checkbox values to a textarea. Code: <script type="text/javascript"> function add_sub(el){ if (el.checked) el.form.elements['type'].value+=el.value; else{ var re=new RegExp('(.*)'+el.value+'(.*)$'); el.form.elements['type'].value=el.form.elements['type'].value.replace(re,'$1$2'); } } </script> </head> <body> <form name="form1" method=post> <textarea name="type" rows="5" cols="35" onclick="this.focus();this.select();"> </textarea><br> <input type="checkbox" name="bob" id="bob" value="<p>" onclick="add_sub(this);"><label for="bob"><p></label><br> <input type="checkbox" name="bob1" id="bob1" value="<span>" onclick="add_sub(this);"><label for="bob1"><span></label><br> <input type="checkbox" name="bob2" id="bob2" value="<div>" onclick="add_sub(this);"><label for="bob2"><div></label> That is working. However, I wanted to put carriage returns after each checkbox value added, so I added the + "\r\n" as follows: Code: <script type="text/javascript"> function add_sub(el){ if (el.checked) el.form.elements['type'].value+=el.value + "\r\n"; else{ var re=new RegExp('(.*)'+el.value+'(.*)$'); el.form.elements['type'].value=el.form.elements['type'].value.replace(re,'$1$2'); } } </script> That is working when adding the value, but removing the value when the checkbox is unchecked is not working. I know the regular expression, etc. needs to be updated to account for the carriage returns, but I have tried everything I can think of and cannot get it to work. Help correcting the code is appreciated. Hello, I'm trying to create a textarea using Javascript, the function creates a textarea in IE, but it does not create that element in Firefox and chrome. JavaScript Code:- Code: function addRow() { alert("function start"); var table = document.getElementById('tableId'); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var textNode = document.createTextNode(rowCount + 1); cell1.appendChild(textNode); var cell2 = row.insertCell(1); var textArea = zxcFormField('TEXTAREA','option1'); textArea.setAttribute("cols","20"); textArea.style.height = "42px"; textArea.style.width = "496px"; cell2.appendChild(textArea); alert("function end"); } function zxcFormField(tag,nme,type){ alert("2 function start"); var el; try { alert("In Try"); el=document.createElement('<'+tag+(type?' type='+type:'')+' name='+nme+' >'); } catch (e){ alert("In Catch"); el=document.createElement(tag); if (type) el.type=type; el.name=nme; } return el; } When I call this function it goes in the catch block in Firefox and Chrome, the textarea is displayed and it disappears with a flash. I've banged my head against wall trying to figure this out. Thanks, Abhishek I am looking for a javascript that when a image is clicked on it clears a textarea
Hi I'm looking for ways to limit the textarea input, I dont want people to enter hundreds of lines cause, i only want them to enter max. 10 lines. I've looked at several javascripts (cause the problem only can be solved by javascript), and came up with this script: http://javascript.internet.com/forms...-textarea.html . It works great and even has a counter how many characters are left to type in. However when I copy paste something, the 'counter' doesnt adjust right away...it does when I try to type in something extra though. Is it possible to make the counter adjust automaticly whenever there is pasted ? I guess you guys have to test to see what I mean. Thanks in advance !! I've done a bit of searching and I can't find the answer to my question. I'm working on a website for my business. I have some basic knowledge of coding but I'm mostly a code cobbler. I find various pieces and put it together and hope it works so take it easy on me. I have some code to display products on my site. It works fine. We just have a lot of products and for me to add each one by hand was getting ridiculous. I finally had the bright idea to use Javascript to generate the code for me and then copy it back into my actual HTML page. Last night I wrote the code below. It works perfectly except I have to constantly "View Source" in order to get the code. I was hoping to cut down on a step or two and have the code go into a TextArea. From there I can just select it and copy it into the HTML file. It should make things a little quicker and most importantly easier. Maybe after that I'll try to figure out how to write function to select everything in the TextArea and copy it to my clipboard. That would make things even faster. Any 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=iso-8859-1" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> function calc (form) { var images = form.images.value; var imagesArray = images.split("\n"); var linebreak = "<br />"; var i=0; var j=0; var a=0; while(i < imagesArray.length) { if(j==0) { document.write (" <!-- -------------------------------------------- -->\n"); document.write (" <div id=\"cols3-top\"></div>\n"); document.write (" <div id=\"cols3\" class=\"box\">\n"); } a++; if(j/2!=1) { if(a==imagesArray.length) { document.write ("\n <!-- ---------------- -->\n\n"); document.write (" <div class=\"col last\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); document.write (" </div>\n"); document.write (" <div id=\"cols3-bottom\"></div>\n"); document.write (" <!-- /Columns End Here -->\n\n\n"); break; } else { document.write ("\n <!-- ---------------- -->\n"); document.write (" <div class=\"col\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); i++; j++; } } else { document.write ("\n <!-- ---------------- -->\n\n"); document.write (" <div class=\"col last\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); document.write (" </div>\n"); document.write (" <div id=\"cols3-bottom\"></div>\n"); document.write (" <!-- /Columns End Here -->\n\n\n"); i++; j=0; } } document.close(); } </script> </head> <body> <div style="width:960px; margin:0 auto;"> <form name="myform" method="get" action=""> <textarea label="Image Names:"name="images" cols="30" rows="15" onclick="this.value=''" ></textarea> <p> <label> <input type="button" name="calculate" value="Calculate" onClick="calc(this.form)"/> </label> </p> </form> </div> </body> </html> I am trying to create a sample form using javascript. The form has a series of option and a submit button followed by a textarea. When the user clicks the submit button the textarea should be filled with the selected information from the form. I cannot get the textarea to fill with text. I believe the problem lies in the fact that when I submit the form the page refreshes, but I am not sure if that's the case. With this version of the code I actually can't get passed the Room Type. It always says No Room Type selected. Here is my code: 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>Form Sample</title> <link href="default.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> <!-- function checkForm(myForm) { regexp = /^\d\d\/\d\d\/\d{4}$/; numReg = /^\d*$/; str = ""; for (i = 0; i < 5; i++) { if (!myForm.roomType[i].checked) { alert("No Room Type Selected!\nPlease Select Room Type!"); return; } str += "Room Type: "; str += myForm.roomType[i].value + "\n" } str += "Activities: \n"; for (i = 0; i < 4; i++) { if (!myForm.activity[i].checked) { alert("No Activities Selected!\n Please Select Activities!"); return; } str += "\t" + myForm.activity[i].value + "\n"; } if (myForm.hotels.selectedIndex+1 < 1) { alert("No Hotel Selected!\n Please Select a Hotel!"); return; } else { str += "Hotel: "; for (var i = 0; i < myForm.hotels.length; i++) { if (myForm.hotels[i].selected) { str += myForm.hotels[i].value + "\n"; } } } if ( myForm.confname.value == "" || myForm.confname.value == null) { alert("No Conference Name Entered! Please Enter a Conference Name!"); return; } else { str += "Conference Name: " + myForm.confname.value + "\n"; } if (!regexp.test(myForm.date.value)) { alert("Invalid Date"); return; } else { str += "Date: " + myForm.date.value + "\n"; } if (!numReg.test(myForm.zip.value)) { alert("Invalid Zip Code"); return; } else { str += "Zip Code: " + myForm.zip,value + "\n"; } myForm.info.value = str; } </script> </head> <body> <h1>Host your Conference!</h1> <form name="conference" method="post" onsubmit="checkForm(this); return false;" action="#"> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Select Room Type Type:<br /> </div> <div style="color:#FFCC00; font-weight:bold;"> <input type="radio" name="roomType" value="Large Meeting Room" />Large Meeting Room<br /> <input type="radio" name="roomType" value="Small Meeting Room" />Small Meeting Room<br /> <input type="radio" name="roomType" value="Video Conference Room" />Video Conference Room<br /> <input type="radio" name="roomType" value="Theater Lecture Hall" />Theatre Lecture Hall<br /> <input type="radio" name="roomType" value="Convention Center" />Convention Center<br /> </div> <br /> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Select Activities:<br /> </div> <div style="color:#FFCC00; font-weight:bold;"> <input type="checkbox" name="activity" value="Swimming" />Swimming<br /> <input type="checkbox" name="activity" value="lecture" />Lecture<br /> <input type="checkbox" name="activity" value="Golf" />Golf (Gentlemen Only Ladies Forbidden)<br /> <input type="checkbox" name="activity" value="Tour of the Facilities" />Tour of the Facilities<br /> </div> <br /> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Select Hotel:<br /> </div> <div style="color:#FFCC00; font-weight:bold;"> <select name="hotels" size="4"> <option name="marriott" value="Marriot">Marriott</option> <option name="doubleTree" value="Double Tree">Double Tree</option> <option name="comfortSuites" value="Comfort Suites">Comfort Suites</option> <option name="sheraton" value="Sheraton">Sheraton</option> </select> </div> <br /> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Confence Name: <input type="text" name="confname" size="60" /> </div> <br /> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Zip Code: <input type="text" name="zip" size="12" value="Enter Zip Code"/> </div> <br /> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Date: <input type="text" name="date" size="10" value="mm/dd/yyyy" /> </div> <br /> <div> <input name="confSubmit" type="submit" style="background:#CCCCCC !important; color:#333333 !important;" value="It's Conference Time!" /> <input name="confReset" type="reset" style="background:#CCCCCC !important; color:#333333 !important;" value="Reset Form" onclick="javascript:return checkForm(this.form);" /> </div> <br /> <div style="font-size:20px; font-weight:bold; color:#FF0000;"> Print This: <textarea type="text" name="info" size="1200" style="vertical-align:text-top; height:175px; width:325px;"> </textarea> </div> </form> </body> </html> And here is a link to the page: Form Sample I am looking for a javascript code for this idea under this message ---------------------------------------------------------------------------------------------------------------------------------------------------- I want to create a kind of shopping website so when you click on a image or text it will add some text to a textarea,, it will include the name of item and price of an item Hi and firstly thank you in advance as I've just joined this forum in search of technical help. I am working on a website and having some problems with javascript that creates tabbed content on a page. The script is a free script from http://nuevvo.com/labs/simpletabs/. The problem is that the page with the script is not showing properly. The issue seems to only happen in Internet Explorer. The site was created on a development server and then copied over to the current hosting. The page appeared fine on the development server but when transferred to the new server the problem showed up. Please look at the following in Internet Explorer: This is how the page should look: http://www.sourcescotland.com/nobles...ing-times.html But on the new server it looks like this: http://www.galleyoflorne.co.uk/noble...ing-times.html The code is he Code: <script type="text/javascript" src="scripts/simpletabs_1.3.packed.js"></script> The actual code file is he http://www.galleyoflorne.co.uk/noble..._1.3.packed.js I would be willing to offer paid help if this is necessary. Or at least get to know you so that I can offer you work in future. I don't have anyone on my team yet that specialises in Javascript. thanks so much, Deb I'm currently in the process of updating our old website as the layout is just terrible and it's hard to find products on it. This new layout has drop down menus, accordion menus and an image enlarger all from JavaScript. They work wonders in Firefox and Google chrome but, as usual, Internet Explorer has decided not to load it right for me. I've got several problems... Images won't show up most of the time Not able to click on linked images and the links from the drop down menu Accordion menu won't work, it just displays as one long sidebar When it does work, it shows a big gap between each main header rather than keeping them close together The drop list from the drop down menu hides behind the accordion menu Is there anything I can do that makes IE accept the javascripts? Unfortunately the new layout isn't up live so I've nothing you can link to. However, if there's any coding that you need I'll be more than happy to post it on. Thanks for your time! Hi All, As usual.. I'm not exactly sure what I am doing, I have the right ideas yet nothing is working how i want.. 1- Need the message "Welcome" to cycle through all different 20 styles I created 2- Need the message "Welcome to randomly cycle though all different styles I think I am over complicating this... And i lookeded over quite a number of times thinking I have it right.. I guess I don't since nothing is working Please note I have a separate css file called colors.css with 20 styles PHP Code: <html> <head> <title>Assignment 7</title> <link href="colors.css" rel="stylesheet" type="text/css"></link> <script> var index = 0; var randomindex = 0; function stylize() { index++; if (index > 20) index = 1; var s = "myStyle" + index; var e = "document.getElementsById("Text"); e.className = s; setTimeout("stylize()", 1500); return; } function random() { if (randomindex > 20) index = 1; var b = "myStyle" + randomindex; var c = "document.getElementsById("Text1"); c.className = b; randomindex = Math.floor(Math.random() * 20); document.getElementsbyId("Text1"); setTimeout("random()", 1500); return; } </script> </head> <body onLoad="stylize(); random()"> <table align="center" border="1" bordercolor="black"> <tr> <td align="center"> <font size="3"><b>Examples Below</b></font> </td> </tr> <tr> <td align="center" height="100" width="400"> <div id="Text" class="myStyle1"> Watch! </div> </tr> </table> <br><br> <table align="center" border="1" bordercolor="black"> <tr> <td align="center"> <font size="3"><b>Examples Below</b></font> </td> </tr> <tr> <td align="center" height="100" width="400"> <div id="Text1" class="myStyle1"> Welcome </div> </tr> </table> </body> </html> There's 2 problems i'm having with this code. 1. foodArray is a multidimensional array that is initialized with 13 elements at the start. When i load the page, the body onload event calls the fillTable function, which fills the table with the first 5 elements of foodArray. If i then click the next button in the bottom right corner, it shows the next 5 elements of foodArray by again calling the fillTable function, incrementing page variable by 1. If I press next a 3rd time it shows the last 3 items of foodArray, but it does not overwrite the last 2 rows of the output table that were filled with the previous second call to the fillTable function. This should happen because there are no elements in foodArray[13] and foodArray[14], and i tried to write the fillTable function to detect when the array is undefined and output dashes instead. How do i fix the fillTable function to overwrite these last 2 rows when the array is empty? the fillTable function seems to be crashing when it reaches these last 2 rows. 2. The second problem is simpler. Each add button in the table has a unique id defined by the fillTable function. When i click on one of these buttons, its supposed to call function add, which is supposed to turn the table cell with the add button clicked to a yellow background. what's wrong with it? Thanks in advance, G 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> <style type="text/css"> #content1 { position: absolute; right: 10px; z-index: 1; top: 100px; } </style> <link href="basicstyle.css" rel="stylesheet" type="text/css" /> <link href="advancestyle.css" rel="stylesheet" type="text/css" /> <link href="tablestyle.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var food1 = new Array("-", "100% Parmesan Cheese", "Kraft", "Dairy & Alternatives", "2 Tbsp", "12g", 45, 2.5, 1.5, 0.1, 5, 230, 1, 0, 0, 5); var food2 = new Array("-", "100% Whole wheat bread", "Dempsters", "Grain Products", "2 slices", "71g", 180, 2, 0.5, 0, 0, 240, 33, 4, 3, 7); var food3 = new Array("-", "Canned Cut Asparagus", "Selection", "Fruit & Vegetables", "1/2 cup", "125mL", 25, 0.3, 0, 0, 0, 260, 4, 2, 2, 2); var food4 = new Array("-", "Chinese Fried Rice", "Uncle Ben's Fast & Fancy", "Grain Products", "1/4 package", "42g", 150, 0.5, 0.2, 0, 0, 370, 33, 1, 1, 3); var food5 = new Array("-", "Cooked Turkey Breast", "Pillar's", "Meat & Alternatives", "2 slices", "40g", 40, 0.5 ,0.3, 0, 20, 460, 1, 0, 1 ,8); var food6 = new Array("-", "Diet Coke", "Coke", "Beverages", "-", "250mL", 0, 0, 0, 0, 0, 35, 0, 0, 0, 0.1, "-"); var food7 = new Array("-", "Honey Nut O's Cereal", "Selection", "Grain Products", "3/4 cup", "30g", 120, 0.5, 0, 0, 0, 150, 26, 2, 12, 2); var food8 = new Array("-", "Hot dogs", "Schneider's", "Meat & Alternatives", "1 wiener", "37g", 120, 10, 3.5, 0.1, 20, 410, 2, 0, 0, 5); var food9 = new Array("-", "Milk Chocolate Crispie Joys", "Harry London", "Treats", "About 4", "40g", 190, 10, 6, 0, 5, 55, 26, "<1g", 18, 3); var food10 = new Array("-", "Mozzarella cheese", "Black Diamond", "Dairy & Alternatives", "1/4 inch cube", "30g", 110, 8, 5, 0.2, 25, 230, 1, 0, 0, 8); var food11 = new Array("-", "Pancake and Waffle Mix", "Selection", "Grain Products", "1/3 cup", "34g", 120, 1.5, 0.4, 0, 15, 510, 23, 1, 3, 3); var food12= new Array("-", "Rancher's Choice Calorie Wise", "Kraft", "Oils & Fats", "1 Tbsp.", "15mL", 35, 2.5, 0.4, 0, 5, 170, 3, 0, 1, 0.1); var food13 = new Array("-", "Strawberry Cereal Bars", "Selection", "Grain Products", "1 bar", "38g", 130, 2.5, 0.2, 0, 5, 210, 25, 3, 10, 2); var foodArray = [food1, food2, food3, food4, food5, food6, food7, food8, food9, food10, food11, food12, food13]; var resultArray = [ [ ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ] ]; var arrayToSearch = [ [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ] ]; var arrayRows; var arrayColumns; var outputTableRows; var outputTableColumns; var page = 1; var resultCount = 0; function fillTable( arr, p ) { //fill the output table with whatever array is passed to it in form of arr parameter. outputTableRows = 5; outputTableColumns = 16; for (var x = 0; x < outputTableRows; x++) { var xPage = (x + 5 * (p - 1)); for (var y = 0; y < outputTableColumns; y++) { //set id variable in order to refer to each cell in the output table by this id. var id = x + "_" + y; if ( (arr[xPage][y] != undefined) ) { //if its the first column, put in a button, or else put in the resultArray[x][y] value in the output table cell. if (y == 0) document.getElementById(id).innerHTML = "<input id=\"b" + id + "\" type=\"button\" value=\"add\" onclick=\"add()\">"; else document.getElementById(id).innerHTML = arr[xPage][y]; //else if the resultArray entry is undedefined, just put in a dash in the output table cell. } else { document.getElementById(id).innerHTML = "-"; } } } } // why wont this work???????????????????????????????????????? function add( e ) { alert("Add"); if (!e) var e = window.event; var callerId = this.id; alert(callerId); this.parent.style.backgroundColor = "yellow"; } function searchArray() { //search the array containing all database food items (foodArray), a 2 dimensional array. //find array entries that match search results. //put search results into 2 dimesional array foodArray. //display foodArray in output table. //re-intitialize resultArray to empty it, and resultCount to 0. var resultArray = [ [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ] ]; var arrayToSearch = [ [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ], [ , ] ]; resultCount = 0; page = 1; //get search terms. food = document.getElementById("foodsearch").value; brand = document.getElementById("brandsearch").value; foodType = document.getElementById("foodtypesearch").value; //set rows and columns dynamiically and for the output table //this uses foodArray to start. //only works if all rows of foodArray have the correct length, because always uses the first row to count length. arrayRows = foodArray.length; arrayColumns = foodArray[0].length; outputTableRows = 5; outputTableColumns = 16; //if a search term is entered for food if (food != "") { //for each row in the foodArray table for (var x = 0; x < arrayRows; x++) { //search the second column of each foodArray item for the search term. var result = foodArray[x][1].indexOf(food); //if a match was found, put the result into a new row for resultArray referred to by resultCount. if (result != -1) { for (var y = 0; y < arrayColumns; y++) { resultArray[resultCount][y] = foodArray[x][y]; } resultCount += 1; } } fillTable( resultArray, page ); } //if a search term is entered for brand if (brand != "") { //for each row in the foodArray table for (var x = 0; x < arrayRows; x++) { //search the second column of each foodArray item for the search term. var result = foodArray[x][2].indexOf(brand); //if a match was found, put the result into a new row for resultArray referred to by resultCount. if (result != -1) { for (var y = 0; y < arrayColumns; y++) { resultArray[resultCount][y] = foodArray[x][y]; } resultCount += 1; } } fillTable ( resultArray, page ); } //if a search term is entered for foodType if (foodType != "") { //for each row in the foodArray table for (var x = 0; x < arrayRows; x++) { //search the second column of each foodArray item for the search term. var result = foodArray[x][3].indexOf(foodType); //if a match was found, put the result into a new row for resultArray referred to by resultCount. if (result != -1) { for (var y = 0; y < arrayColumns; y++) { resultArray[resultCount][y] = foodArray[x][y]; } resultCount += 1; } } fillTable ( resultArray, page ); } } function resetSearch() { page = 1; fillTable ( foodArray, page ); document.getElementById("foodsearch").value = ""; document.getElementById("brandsearch").value = ""; document.getElementById("foodtypesearch").value = ""; } function start() { alert("Start pressed"); page = 1; fillTable ( foodArray, page ); } function last() { alert("Last"); page -= 1; fillTable ( foodArray, page ); } function next() { alert("Next"); page += 1; fillTable ( foodArray, page ); } function end() { alert("End"); page = 3; fillTable ( foodArray, page ); } </script> </head> <body onload="fillTable( foodArray, 1 )"> <div id="dcontainer" class="type3div"> <div id="dheader" class="type2div"> <div id="dlogo" class="type1div"></div> <div id="dlogin" class="type1div"></div> </div> <div id="dmenubar" class="type2div"> <a href=""><div id="dmenu1" class="navigation">Page 1</div></a> <a href=""><div id="dmenu2" class="navigation">Page 2</div></a> <a href=""><div id="dmenu3" class="navigation">Page 3</div></a> <a href=""><div id="dmenu4" class="navigation">Page 4</div></a> <a href=""><div id="dmenu5" class="navigation">Page 5</div></a> </div> <div id="dcontent" class="type2div"> <h1>Grocery Store Aisle 1: Select food items from a database</h1> <div id="content1" class="type1div"> <div id="legend"> <table border="1"> <tr> <td colspan="2" align="center"><b>Legend</b></td> </tr> <tr> <td>SS = Serving Size</td><td>Sod = Sodium</td> </tr> <tr> <td>Cal = Calories</td><td>Carb = Carbohydrate</td> </tr> <tr> <td>Fat = Fat</td><td>Fib = Carbohydrate: Fibre</td> </tr> <tr> <td>Sat = Fat: Saturated</td><td>Sug = Carbohydrate: Sugars</td> </tr> <tr> <td>Trans = Fat: Trans</td><td>Pro = Protein</td> </tr> <tr> <td>Chol = Cholesterol</td><td style="background-color: yellow">Items in yellow are already in your fridge</td> </tr> </table> </div> </div> <div id="content2" class="type1div"> <div id="search"> <h2>Search Aisle 1</h2> <form id="form1" name="form1" method="post" action=""> <table border="1"> <tr> <td>Food:</td> <td><input id="foodsearch" type="text" size="30" /></td> </tr> <tr> <td>Brand:</td> <td><input id="brandsearch" type="text" size="30" /></td> </tr> <tr> <td>Food Type:</td> <td><input id="foodtypesearch" type="text" size="30" /></td> <tr> <td colspan="2" align="right"> <input id="resetsearch" type="button" size="20" value="Reset Search" onclick="resetSearch()" /> <input id="gosearch" type="button" size="20" value="Search" onclick="searchArray()" /> </td> </tr> </table> </form> </div> </div> <div id="content3" class="type1div"> <h2>Results</h2> <div id="table1" class="outputTable"> <table border="1"> <thead> <tr> <th class="tableHeadMediumCenter">Edit</th> <th class="tableHeadLargeLeft">Food</th> <th class="tableHeadLargeLeft">Brand</th> <th class="tableHeadLargeLeft">Food Type</th> <th class="tableHeadLargeLeft">Serving Amount</th> <th class="tableHeadSmallCenter">SS</th> <th class="tableHeadSmallCenter">Cal</th> <th class="tableHeadSmallCenter">Fat</th> <th class="tableHeadSmallCenter">Sat</th> <th class="tableHeadSmallCenter">Trans</th> <th class="tableHeadSmallCenter">Chol</th> <th class="tableHeadSmallCenter">Sod</th> <th class="tableHeadSmallCenter">Carb</th> <th class="tableHeadSmallCenter">Fib</th> <th class="tableHeadSmallCenter">Sug</th> <th class="tableHeadSmallCenter">Pro</th> </tr> </thead> <tbody> <tr> <td id="0_0" class="tableCellCenterTop">-</td> <td id="0_1" class="tableCellLeftTop">-</td> <td id="0_2" class="tableCellLeftTop">-</td> <td id="0_3" class="tableCellLeftTop">-</td> <td id="0_4" class="tableCellLeftTop">-</td> <td id="0_5" class="tableCellCenterTop">-</td> <td id="0_6" class="tableCellCenterTop">-</td> <td id="0_7" class="tableCellCenterTop">-</td> <td id="0_8" class="tableCellCenterTop">-</td> <td id="0_9" class="tableCellCenterTop">-</td> <td id="0_10" class="tableCellCenterTop">-</td> <td id="0_11" class="tableCellCenterTop">-</td> <td id="0_12" class="tableCellCenterTop">-</td> <td id="0_13" class="tableCellCenterTop">-</td> <td id="0_14" class="tableCellCenterTop">-</td> <td id="0_15" class="tableCellCenterTop">-</td> </tr> <tr> <td id="1_0" class="tableCellCenterTop">-</td> <td id="1_1" class="tableCellLeftTop">-</td> <td id="1_2" class="tableCellLeftTop">-</td> <td id="1_3" class="tableCellLeftTop">-</td> <td id="1_4" class="tableCellLeftTop">-</td> <td id="1_5" class="tableCellCenterTop">-</td> <td id="1_6" class="tableCellCenterTop">-</td> <td id="1_7" class="tableCellCenterTop">-</td> <td id="1_8" class="tableCellCenterTop">-</td> <td id="1_9" class="tableCellCenterTop">-</td> <td id="1_10" class="tableCellCenterTop">-</td> <td id="1_11" class="tableCellCenterTop">-</td> <td id="1_12" class="tableCellCenterTop">-</td> <td id="1_13" class="tableCellCenterTop">-</td> <td id="1_14" class="tableCellCenterTop">-</td> <td id="1_15" class="tableCellCenterTop">-</td> </tr> <tr> <td id="2_0" class="tableCellCenterTop">-</td> <td id="2_1" class="tableCellLeftTop">-</td> <td id="2_2" class="tableCellLeftTop">-</td> <td id="2_3" class="tableCellLeftTop">-</td> <td id="2_4" class="tableCellLeftTop">-</td> <td id="2_5" class="tableCellCenterTop">-</td> <td id="2_6" class="tableCellCenterTop">-</td> <td id="2_7" class="tableCellCenterTop">-</td> <td id="2_8" class="tableCellCenterTop">-</td> <td id="2_9" class="tableCellCenterTop">-</td> <td id="2_10" class="tableCellCenterTop">-</td> <td id="2_11" class="tableCellCenterTop">-</td> <td id="2_12" class="tableCellCenterTop">-</td> <td id="2_13" class="tableCellCenterTop">-</td> <td id="2_14" class="tableCellCenterTop">-</td> <td id="2_15" class="tableCellCenterTop">-</td> </tr> <tr> <td id="3_0" class="tableCellCenterTop">-</td> <td id="3_1" class="tableCellLeftTop">-</td> <td id="3_2" class="tableCellLeftTop">-</td> <td id="3_3" class="tableCellLeftTop">-</td> <td id="3_4" class="tableCellLeftTop">-</td> <td id="3_5" class="tableCellCenterTop">-</td> <td id="3_6" class="tableCellCenterTop">-</td> <td id="3_7" class="tableCellCenterTop">-</td> <td id="3_8" class="tableCellCenterTop">-</td> <td id="3_9" class="tableCellCenterTop">-</td> <td id="3_10" class="tableCellCenterTop">-</td> <td id="3_11" class="tableCellCenterTop">-</td> <td id="3_12" class="tableCellCenterTop">-</td> <td id="3_13" class="tableCellCenterTop">-</td> <td id="3_14" class="tableCellCenterTop">-</td> <td id="3_15" class="tableCellCenterTop">-</td> </tr> <tr> <td id="4_0" class="tableCellCenterTop">-</td> <td id="4_1" class="tableCellLeftTop">-</td> <td id="4_2" class="tableCellLeftTop">-</td> <td id="4_3" class="tableCellLeftTop">-</td> <td id="4_4" class="tableCellLeftTop">-</td> <td id="4_5" class="tableCellCenterTop">-</td> <td id="4_6" class="tableCellCenterTop">-</td> <td id="4_7" class="tableCellCenterTop">-</td> <td id="4_8" class="tableCellCenterTop">-</td> <td id="4_9" class="tableCellCenterTop">-</td> <td id="4_10" class="tableCellCenterTop">-</td> <td id="4_11" class="tableCellCenterTop">-</td> <td id="4_12" class="tableCellCenterTop">-</td> <td id="4_13" class="tableCellCenterTop">-</td> <td id="4_14" class="tableCellCenterTop">-</td> <td id="4_15" class="tableCellCenterTop">-</td> </tr> </tbody> </table> </div> <div id="scroll"> <span onclick="start()">‹‹Start</span> <span onclick="last()">‹Last</span> <span onclick="next()">Next›</span> <span onclick="end()">End››</span> </div> </div> </div> </div> </body> </html> Bear with me as this is my first post but i am not sure what this is about. My computer seems to have problems with its javascript when opening new windows from certain sites that are either audio or video files. I simply have not got a clue where to begin. Any help ould be most grateful. I am having a problem with the follow code with IE9 only. Works fine with any other browser.. Any help? Thanks <a href="javascript:var w = window.open('show_photo.php?ad_id={AD_ID}&img_id={IMG_ID}','','width=450,height=500,toolbar=0,scroll bars=0,statusbar=0,menubar=0,resizable=0');"> </a> sorry for my poor english I have 2 boxfield in my search engine...when i write somthing on my 1st text box and press the clear button it clear me the thing i wrote in the text field.... when i write somthing and drag it from 1st text box to the 2nd and then press the clear button.the letter in the 2nd textfield jump the 1st one.....and doesnt clear herself... what can couse it ? |