JavaScript - Javascript Help Needed For Category Image Display And Delete Dynamically
I have search for about a week and still no luck.
I need to dynamically display mutliple images using javascript, no hardcoding. The images have different categories. For ex. bellTower01.jpg, bellTower02.jpg...and fountain01.jpg, fountain02.jpg.... -Use JavaScript to display several images and scroll through them To display multiple thumbnails, arrange them into a small quantity (no more than 8 per page) Provide pagination I really really really need help. I have never done javascript before, so I'm still learning. I seriously checked out many threads and links but nothing works or is what I want. I hope someone can help me out and hopefully also allow me to become better at coding this kind of stuff. I am not allowed to code in php for this project. I can only use javascript to display the images. Also, I don't really need anything fancy, like slideshows or rotations, I just the image to appear when I select that specific category. I want to get the images from my folder/directory. Right now, I have it working as it just being hardcoded. Below is my code for my galleries page: <?php //creates a session..initializes session data session_start (); echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); ?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Scenes of Purdue</title> <!-- Styling of the Webpage --> <link rel="stylesheet" type="text/css" href="css/style.css"/> <script src="js/prototype.js" type="text/javascript"></script> <script src="js/scriptaculous.js?load=effects,builder" type="text/javascript"></script> <script src="js/lightbox.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="css/lightbox.css"/> </head> <body> <div id="shadowContainer"> <div id="mainContainer"> <div id="mainHeader"></div> <div id="topNav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="galleries.php">Galleries</a></li> </ul> </div><div id="content"> <br /> <div class="clearfix"><h1>Select a Category to View</h1> <br /> <div class="paginationBar" id="paginationBar"> <select id="catDropDown" onchange="javascript:getCategory()"> <option value="-" selected="selected">Select a Category</option> <option value="bellTower">Bell Tower</option> <option value="fountain">Fountain</option> </select> </div> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <br /><br /> <ul id="pagination"> </ul> <div id="r1c1"></div> <div id="r1c2"></div> <div id="r1c3"></div> <div id="r2c1"></div> <div id="r2c2"></div> <div id="r2c3"></div> <script type="text/javascript"><!-- var bellTowerArray = new Array(); bellTowerArray[0] = "bellTower01.jpg"; bellTowerArray[1] = "bellTower02.jpg"; bellTowerArray[2] = "bellTower03.jpg"; bellTowerArray[3] = "bellTower04.jpg"; bellTowerArray[4] = "bellTower05.jpg"; bellTowerArray[5] = "bellTower06.jpg"; bellTowerArray[6] = "bellTower07.jpg"; bellTowerArray[7] = "bellTower08.jpg"; bellTowerArray[8] = "bellTower09.jpg"; bellTowerArray[9] = "bellTower10.jpg"; bellTowerArray[10] = "bellTower11.jpg"; bellTowerArray[11] = "bellTower12.jpg"; bellTowerArray[12] = "bellTower13.jpg"; bellTowerArray[13] = "bellTower14.jpg"; bellTowerArray[14] = "bellTower15.jpg"; bellTowerArray[15] = "bellTower16.jpg"; var fountainArray = new Array(); fountainArray[0] = "fountain01.jpg"; fountainArray[1] = "fountain02.jpg"; fountainArray[2] = "fountain03.jpg"; fountainArray[3] = "fountain04.jpg"; fountainArray[4] = "fountain05.jpg"; fountainArray[5] = "fountain06.jpg"; fountainArray[6] = "fountain07.jpg"; fountainArray[7] = "fountain08.jpg"; fountainArray[8] = "fountain09.jpg"; fountainArray[9] = "fountain10.jpg"; fountainArray[10] = "fountain11.jpg"; fountainArray[11] = "fountain12.jpg"; fountainArray[12] = "fountain13.jpg"; fountainArray[13] = "fountain14.jpg"; fountainArray[14] = "fountain15.jpg"; fountainArray[15] = "fountain16.jpg"; fountainArray[16] = "fountain17.jpg"; fountainArray[17] = "fountain18.jpg"; var currentArray = new Array(); function getCategory() { if(document.getElementById("catDropDown").selectedIndex == 1) { currentArray = bellTowerArray; } else if(document.getElementById("catDropDown").selectedIndex == 2) { currentArray = fountainArray; }//if/else if(document.getElementById("catDropDown").selectedIndex > 0) { displayImages(0); doPagination(); } } function displayImages(start) { //r1c1 if(!(start > currentArray.length-1)) document.getElementById("r1c1").innerHTML = "<a id=\"r1c1_a\" href=\"images/regular/" + currentArray[start] + "\" rel=\"lightbox\" title=\"This is the static description\"><img src=\"images/th/thumb_" + currentArray[start] + "\" id=\"r1c1_img\" width=\"150\" height=\"150\" alt=\"This is the static description in alt\" title=\"Static title description\" /><"+"/a>"; else document.getElementById("r1c1").innerHTML = ""; //r1c2 if(!(start+1 > currentArray.length-1)) document.getElementById("r1c2").innerHTML = "<a id=\"r1c2_a\" href=\"images/regular/" + currentArray[start+1] + "\" rel=\"lightbox\" title=\"This is the static description\"><img src=\"images/th/thumb_" + currentArray[start+1] + "\" id=\"r1c2_img\" width=\"150\" height=\"150\" alt=\"This is the static description in alt\" title=\"Static title description\" /><"+"/a>"; else document.getElementById("r1c2").innerHTML = ""; //r1c3 if(!(start+2 > currentArray.length-1)) document.getElementById("r1c3").innerHTML = "<a id=\"r1c3_a\" href=\"images/regular/" + currentArray[start+2] + "\" rel=\"lightbox\" title=\"This is the static description\"><img src=\"images/th/thumb_" + currentArray[start+2] + "\" id=\"r1c3_img\" width=\"150\" height=\"150\" alt=\"This is the static description in alt\" title=\"Static title description\" /><"+"/a>"; else document.getElementById("r1c3").innerHTML = ""; //r2c1 if(!(start+3 > currentArray.length-1)) document.getElementById("r2c1").innerHTML = "<a id=\"r2c1_a\" href=\"images/regular/" + currentArray[start+3] + "\" rel=\"lightbox\" title=\"This is the static description\"><img src=\"images/th/thumb_" + currentArray[start+3] + "\" id=\"r2c1_img\" width=\"150\" height=\"150\" alt=\"This is the static description in alt\" title=\"Static title description\" /><"+"/a>"; else document.getElementById("r2c1").innerHTML = ""; //r2c2 if(!(start+4 > currentArray.length-1)) document.getElementById("r2c2").innerHTML = "<a id=\"r2c2_a\" href=\"images/regular/" + currentArray[start+4] + "\" rel=\"lightbox\" title=\"This is the static description\"><img src=\"images/th/thumb_" + currentArray[start+4] + "\" id=\"r2c2_img\" width=\"150\" height=\"150\" alt=\"This is the static description in alt\" title=\"Static title description\" /><"+"/a>"; else document.getElementById("r2c2").innerHTML = ""; //r2c3 if(!(start+5 > currentArray.length-1)) document.getElementById("r2c3").innerHTML = "<a id=\"r2c3_a\" href=\"images/regular/" + currentArray[start+5] + "\" rel=\"lightbox\" title=\"This is the static description\"><img src=\"images/th/thumb_" + currentArray[start+5] + "\" id=\"r2c3_img\" width=\"150\" height=\"150\" alt=\"This is the static description in alt\" title=\"Static title description\" /><"+"/a>"; else document.getElementById("r2c3").innerHTML = ""; } function doPagination() { var numpages = (currentArray.length / 6) +1; var numleft = currentArray.length % 6; document.getElementById("pagination").innerHTML = ""; for(i=0; i<numpages-1; i++) { document.getElementById("pagination").innerHTML += "<span onclick='displayImages("+ i*6 +")'>"+ (i+1) + "<"+"/span> "; } if(numpages <=1) { document.getElementById("pagination").innerHTML = ""; } } document.getElementById("catDropDown").selectedIndex = 0; --> </script> </div> </div> </div> <div id="footer"><a href="readme.php">Readme</a><br /> <div class="clearfix"> <div style="float: left"><a href="adminLogin.php" title="Admin Login" class="adminLoginAjax">Admin login</a></div> </div> </div> </div> </div> </body> </html> Similar Tutorialshi this is santosh first off all thanks in advance to all who r reading my question im in prblm in my project in 1 file i have to first display textbox in html statically which will hav + & - button preceding it , & on click of + button one more textbox should appear dynamically & first textbox + button should disapper & it should hav only - button & the textbox which was dynamically generated now on click of first textbox + button should hav + & - button & it should go on. & on click of - button textbox which is in front of it should get deleted. here i tried alot but my code is showing + & - button to every textbox that is dynamically generated which is not the requirement plz help me im in great need. earlier also i hav submitted my queries & got a fully satisfied result bcoz of that now im having great hopes from u & this site plz reply as early as possible waiting for ur reply again thanks in advance http://www.javascriptkit.com/javatut...rnalphp2.shtml Anyone have a decent way of adding a fade affect to this script? I have a table that has a series of dropdowns. Each dropdown is build with JavaScript based on the values of the prior dropdowns. The data for each of these dropdowns comes from a series of XML files which are loaded into a series of arrays on loading. This is all working. What I need (but can't figure out) is how to dynamically build a sub-table within a specific cell of the parent table based on the values of the prior dropdowns and if the prior dropdowns are changed, how do delete (not just hide) the dynamic table and rebuild it based on the values of the new dropdowns. 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 Hello, First, I'm new to the Javascript (and to this forum). I am trying to use a Javascript to display a randomly selected image located in a folder of my site. I need to fit these images (which may have quite diverse dimensions) into a frame of 280x280 px. Here is the code of the current script which does not currently work: Code: // JavaScript Document <script language="JavaScript"><!-- function random_imglink(){ var myimages=new Array() var imagetitle=new Array() urlimage="http://www.mysite.fr/Images/RandomPictures/" var i=0 //specify here the total number of random images which should be names 1.jpg, 2.jpg etc nbrandompic=140 for (i=0;i<= nbrandompic;i++) { myimages[i]=urlimage + i +".jpg" imagetitle[i]=urlimage + i +".txt" } //Randomly select an image var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 var reduction = 1 var maxWidth=280 var maxHeight=280 //Calculate the reduction that should be applied if(myimages[ry].width > maxWidth || image.height > maxHeight) reduction = Math.max(myimages[ry].width/maxWidth,myimages[ry].height/maxHeight) // New dimensions iw = Math.round(myimages[ry].width / reduction) ih = Math.round(myimages[ry].height / reduction) //Display image document.write('<a><img src="'myimages[ry]'" title="" border=0 width='+iw+' height='+ih+'></a>') } random_imglink() //--> </script> I am sure that you guys can help me solve this problem. Many thanks in advance!! Antonino Hi guys I'm really stumped on this, and I haven't been able to find a tutorial online anywhere. I'm trying to create an XML news feed for a company's website I am currently building. I have created the XML, and gotten the text to display perfectly in the HTML by using javascript. Now I want to add a thumbnail image for each news story, to make updating simpler, I wanted the url for the thumbnail to be entered into the XML, from which the javascript could read and then display in the corresponding area in the HTML. Is this even possible? Every tutorial I get when I use the terms "Image" and "Javascript" gives me a tutorial for a gallery or a slideshow which is not what I want at all. Below is the javascript code, followed by the XML code; Code: <script type="text/javascript"> var xmlDoc; <!-- if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","SDS.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; var x=xmlDoc.getElementsByTagName("NEWS"); i=0; function display() { title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue.fontsize("5").fontcolor("white").bold()); date=(x[i].getElementsByTagName("DATE")[0].childNodes[0].nodeValue.fontsize("2").fontcolor("white").bold()); stitle=(x[i].getElementsByTagName("STITLE")[0].childNodes[0].nodeValue.fontsize("3").fontcolor("white").italics()); story=(x[i].getElementsByTagName("STORY")[0].childNodes[0].nodeValue.fontsize("3").fontcolor("white")); txt= title + "<br />" + date + "<br />" + stitle + "<br />" + story; document.getElementById("show").innerHTML=txt; } //--> </script> XML code Code: <?xml version="1.0" encoding="ISO-8859-1"?> <BULLETIN> <NEWS> <PIC>"/newssmall.jpg"</PIC> <DATE>14/3/2010</DATE> <TITLE>News Story 1</TITLE> <STITLE>This is a short sentence to describe the story in brief</STITLE> <STORY>This is the text of the news story</STORY> </NEWS> </BULLETIN> Thanks to anyone that even reads this, I'm probably making a nooby mistake, I only started using JS and XML on Monday so I'm still learning lol Does anyone know the code/script that is used for the image slider and the category switcher (where it says Our Games) as seen on http://en.popmog.com/games? I have no idea how to create something similar on my own site.
I need to display a set of photos in a limited space. After some online search, I haven't found a suitable Javascript code for the task. I would like to have something similar with the image slider on meetup.com. Basically, I would like to have an image index list and able to display an image in a large size. Any recommendations? Thanks in advance for your inputs. Ok got a random image display and have tried to make it so once the image is displayed it is taken out of the array so it can not be viewed again untill there are no more elements in the array, problem is, it doesn't work. Have been told about shuffle, but not very keen on that. Can someone shed some light. 4 images, with accompaning links to be displayed 4 times, all unique. Code: Code: <script language="JavaScript"> function random_imglink(){ var myimages=new Array() myimages[0]="http://ads.factorymedia.com/www/images/fbm_oct10_300x80.gif" myimages[1]="http://ads.factorymedia.com/www/images/rbbyd_web_banner_300x80_animated.gif" myimages[2]="http://ads.factorymedia.com/www/images/2010_vex_300x80.jpg" myimages[3]="http://ads.factorymedia.com/www/images/image_3.gif" var imagelinks=new Array() imagelinks[0]="http://www.4downdistribution.com/" imagelinks[1]="http://www.redbull.co.uk/cs/Satellite/en_UK/Event/Red-Bull-Backyard-Digger-021242831811513" imagelinks[2]="http://verdebmx.com/" imagelinks[3]="http://www.zealbmx.com/" var count; for(count=0; count<myimages.length; count++) { if (myimages.length>0) { var ry=Math.floor(Math.random()*myimages.length) document.write('<div class="feed2"><a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" height=64px width=240px border=0></a></div>') if (ry>0 && ry<myimages.length-1) { myimages=concat(myimages. (0,ry-1),myimages.slice(ry+1,myimages.length-1)); imagelinks=concat(imagelinks.slice(0,ry-1),imagelinks.slice(ry+1,imagelinks.length-1)); } if (ry==0) { myimages=myimages.slice(1,myimages.length-1); imagelinks=imagelinks.slice(1,imagelinks.length-1); } if (ry==myimages.length-1) { myimages=myimages.slice(0,ry-1); imagelinks=imagelinks.slice(0,ry-1); } } } } </script> <script language="JavaScript"> random_imglink(); </script> an alternative way that also didn't work Code: function random_imglink(){ var myimages=new Array(); myimages[0]="http://ads.factorymedia.com/www/images/fbm_oct10_300x80.gif"; myimages[1]="http://ads.factorymedia.com/www/images/rbbyd_web_banner_300x80_animated.gif"; myimages[2]="http://ads.factorymedia.com/www/images/2010_vex_300x80.jpg"; myimages[3]="http://ads.factorymedia.com/www/images/image_3.gif"; var imagelinks=new Array(); imagelinks[0]="http://www.4downdistribution.com/"; imagelinks[1]="http://www.redbull.co.uk/cs/Satellite/en_UK/Event/Red-Bull-Backyard-Digger-021242831811513"; imagelinks[2]="http://verdebmx.com/"; imagelinks[3]="http://www.zealbmx.com/"; var indexes = [0, 1, 2, 3]; index.sort(function (){ reutrn 0.5 - Math.random(); }); for(var count=0; count < index.length; count++) { var ry = indexes[count]; document.write('<div class="feed2"><a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" height=64px width=240px border=0></a></div>'); } } Hi, I have the following function to dynamically create an image (in this case a toolbox button): Code: function createButton(srcid,bttn) { if (bttn=='mag') {s='Magnify';h='Magnify';o='DoZoom(event,\'0\',\''+srcid+'\')';} if (bttn=='frz') {s='Pause';h='Freeze/Unfreeze';o='setPicture(\''+srcid+'\',0)';} if (bttn=='swp') {s='Swap';h='Swap maps';o='setPicture(\''+srcid+'\',2)';} btn=document.createElement('img'); btn.setAttribute('src','toolbox/'+s+'.gif'); btn.setAttribute('width','16px'); btn.setAttribute('height','16px'); btn.setAttribute('id',bttn+'btn_'+srcid); btn.setAttribute('class','button'); btn.setAttribute('name','Toolbox'); btn.setAttribute('title',h); btn.setAttribute('onclick',o); document.getElementById('ctrlDiv').appendChild(btn); } which works fine in IE8 and IE9, but in IE7 it refuses to pick up the style 'button'. I've even tried putting in btn.class='button' but JS throws up an error. If I specify the style by btn.style.position='Absolute' it picks this up OK. However, it won't respond to the onclick event either. I have heard that setAttribute is buggy with IE7, which is why I tried to specify each attribute directly. The style sheet for class button is: Code: .button { position: absolute; left: 5; top: 5; z-index: 1; } (BTW, no link to a website as this is local on my machine atm) TIA, Gerald. hi i am totally frustrated !! i have been using this on my webpage. http://www.barelyfitz.com/projects/tabber/ if u see under the advanced section there is a code for changing tabs dynamically. Code: document.getElementById('mytab1').tabber.tabShow(0); this doesn't work. basically i have a webpage internet.htm. which has a menubar with loads of menu items. if i click one of the submenu items this code should change the dynamic tabs in admin.htm. the code i have defined for the submenu click is: Code: <li><a href="admin.htm" onClick="document.getElementById('Admin').tabber.tabShow(0)" >Forms</a></li> the full code is: Code: <ul id="QualityMenuBar" class="MenuBarHorizontal"> <li><a class="MenuBarItemSubmenu" href="#"><strong>Admin</strong></a> <ul> <li><a href="AdminDocuments.htm" onClick="document.getElementById("Admin").tabber.tabShow(0)" >Forms</a></li> <li><a href="AdminDocuments.htm" >Guidance</a></li> <li><a href="AdminDocuments.htm" onClick="document.getElementById("Admin").tabber.tabShow(2)" >Organisation Chart</a></li> <li><a href="AdminDocuments.htm">Plans</a></li> <li><a href="AdminDocuments.htm">Procedures</a></li> </ul> </li> this is what the admindocuments.htm contains, based on the website link i have borrowed the code from. Code: <div class="tabber" id="admin"> <div class="tabbertab"> <h2>Forms</h2> <script type="text/javascript" src="adminForms.js"></script> </div> <div class="tabbertab"> <h2>Guidance</h2> <script type="text/javascript" src="adminGuidance.js"></script> </div> <div class="tabbertab"> <h2>Org. Chart</h2> <script type="text/javascript" src="adminOrg.js"></script> </div> <div class="tabbertab"> <h2>Plans</h2> <script type="text/javascript" src="adminPlans.js"></script> </div> <div class="tabbertab"> <h2>Procedures</h2> <script type="text/javascript" src="adminProc.js"></script> </div> </div> whenever i click the submenu they all point to the first tab only. it doesn't change inspite of the code. what am i doing wrong here? please advice. Many thanks. I've done some googling and have come across some information, but I'm not quite sure how to apply it to my problem. I have a PHP page saturna.php with six frames on it using the frameset commands. I would like to somehow make it so that when I click on something in one frame (with one PHP page loaded in it - game.php), it automatically/dynamically updates one of the other PHP pages (inventory.php) in another frame. What will happen is when the thing is clicked on in game.php, an entry will be added to the database, and the second PHP page (which retrieves information from the database) will notice that there is a new relevant record, and will add it to the inventory.php page in the table I have constructed there. From my googling it seems I need to use JavaScript to do this, but I'm not quite sure how - any ideas ? Thanks very much! I am creating a website and there is an option for the user (after he login to the website, he enters into his workspace page)to upload a background image of his choice to his workspace page. Can the user dynamically upload a background image to his webpage? Can this be done in javascript/php? I would be glad if somebody could help me. Hello my first post. I have a function that insert commas via onclick or onblur. Code: function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } I also am using code from this link, where I can specify what parameters to allow the user to enter only positive/negative, decimals values and restricting characters that are not allowed. http://www.mredkj.com/tutorials/validate2.html I am having a hard time to incorporate the addCommas function into the link above. Does anyone have an example that I can look at where I can have commas added to a value dynamically while typing? e.g. if I type 1000 after that last 0 keystroke, it turns the value into 1,000. If I add 3 more zeros it turns it into 1,000,000. In the same vain if I subtract a 0 from the 1,000,000 the value is 100,000 instead. I appreciate any assistance in advance. I currently have a page which, when the user clicks a button creates a new row displaying a form. I also have other forms on this page however so I was wondering if anyone knew how to close a form using javascript? Thanks for any help. My code to create the table row and form are below... Code: myform = document.createElement("form"); myform.method = "post"; myform.action = "editdetails.php"; myform.id = "editemail"; myform.name = "editemail"; var a=document.getElementById('editdetailstable').insertRow(2); var b=document.getElementById('editdetailstable').insertRow(3); var x=a.insertCell(0); x.innerHTML="New Email: "; x.align = "right"; var y=a.insertCell(1); y.innerHTML="<input type='text' name='email' id='email' />"; var z=b.insertCell(0); z.innerHTML="<input type='button' value='Change' />" z.colSpan = "2"; z.align = "center"; I'm attempting to run a small piece of code that will execute one of two source js files on my server. I have no problem creating the proper DOM script object with the proper type and conditional src value. However, when i add it to the document it does not seem to execute. I've tried adding it in two places, both using .appendChild(); myLocation.parentNode.appendChild(newScript); and document.getElementsByTagName("head")[0].appendChild(newScript); (myLocation is a calculated element representing the current script tag) In both these cases, the script tag is added to the document where I intended, but it does not appear to execute. The src has some doc writes in it and the tags the new script should generate right after itself are not there, as they are when I hard code the new sourced script tag into the document. All in all, my confusion comes from the fact that when I write a <script ... src="mysrc.js"></script> into my document, it behaves differently than when I have a script write an identical tag into the document in the same location. Also, fyi, I'm currently using Chrome (though I will require a multi-platform solution). Thanks for your time. I'm new here and this is my first post, I hope I can find help here. How can i dynamically generate this type of form element in javascript, including the table rows and columns enclosing the form elements and whenever that 'Add More' button is clicked, a new instant of the same form will generated and select drop down list populated. I have try to google for solution, but without success. I code in PHP, but i need it to integrate in my code. Thanks for your help. Hi everyone, I am pretty new to JS and I am looking for help writing a function that will dynamically calculate filed values. I have a PHP-generated form which may have a varying number of fields. I need to: 1. calculate the line total for each row -- unitprice * units = linetotal 2. calculate total of all linetotals. I have named my fields as follows: unitprice[1], unitprice[2]... , units[1], units[2], ... I have the following calculate function: Code: function calculateOld() { // get both values unitprice = document.forms["invoice"].unitprice.value; units = document.forms["invoice"].units.value; // do some calculation lineTotal = formatNumber((unitprice * units), 2); // set the value in the right field document.forms["invoice"].linetotal.value = lineTotal; unitprice2 = document.forms["invoice"].unitprice2.value; units2 = document.forms["invoice"].units2.value; if(unitprice2 != '') { // do some calculation lineTotal2 = formatNumber((unitprice2 * units2), 2); // set the value in the right field document.forms["invoice"].linetotal2.value = lineTotal2; document.forms["invoice"].totalprice.value = formatNumber((parseFloat(lineTotal) + parseFloat(lineTotal2)),2); } else { document.forms["invoice"].linetotal2.value = ''; document.forms["invoice"].totalprice.value = formatNumber(lineTotal,2); } } This does calculate what I need but only if I have up to two rows. I need to make the function dynamically count how many rows there are, and calculate the linetotal for each row. And here's where my limited JS knowledge brings me to a halt. I have been thinking about what this new and dynamic function should look like, but that's the best I could produce... Code: function calculate() { var unitprice[i] = document.forms["invoice"].unitprice[i].value; var units[i] = document.forms["invoice"].units[i].value; var linetotal[i] = formatNumber((unitprice[i] * units[i]), 2); return linetotal; } Your help will be appreciated. Please explain how things are done, don't just give me the code. Thanks in advance! Hi CodingForum! For my website, I have a working script that changes the background image of my website every time it is reloaded. However, I would also like the image to dynamically resize as the user resizes the browser window. here is a code snippet: Code: <head> <script type="text/JavaScript"> /*<![CDATA[*/var el="bgImg";var bgimg=new Array("../00home/06home.jpg","../00home/07home.jpg");var random=Math.round((bgimg.length-1)*Math.random());var cssStr="#"+el+" { background: url("+bgimg[random]+") no-repeat center } ";var style=document.createElement("style");style.setAttribute("type","text/css");if(style.styleSheet){style.styleSheet.cssText=cssStr;}else{var cssText=document.createTextNode(cssStr);style.appendChild(cssText);}document.getElementsByTagName("head")[0].appendChild(style);/*]]>*/ </script> <style type="text/css"> .rotatebg { z-index:0; position:fixed; top:0; left:0; width:1378px; height:1178px; background-repeat: no-repeat; background-position:inherit; overflow:hidden; } </style> </head <body> <div class="rotatebg" id="bgImg" style="width:100%; height:100%" ></div> </body> Does anyone know how I can augment/alter this coded setup to enable the randomly loaded background image to proportionately fill the browser window? |