JavaScript - How To Add 2 Seperate Elements In 2 Seperate Arrays?
Hello everyone
I have just found this wonderful forum through Dr Google whilst looking for an answer to my incredibly frustrating question! I am an OU student it is for an assignment I just cannot find the answer in any of the books and searching the net has got me nothing but so far wasted 3 hours Here is the code snippet: Code: // candidates var candidateArray = ['Mr R Green...', 'Ms O Brown...', 'Ms Y Black...', 'Mr G White...', 'Ms B Grey....','Ms I Blue....', 'Mr V Pink....']; // online votes var onlineVotesArray = [21,47,23,11,56,47,30]; // paper votes var paperVotesArray = [12,4,20,11,5,4,17]; //total votes var totalVotesArray = (candidateArray.length); First I had to add a new array called totalVotes and assign a length to it the same as candidateArray, I have done this in the last 2 lines I think this is correct, the question did stipulate that if the candidate array was changed then so would the total votes array hence linking it via length. Now here is where I am at a complete loss The exact wording is as follows: Use a for loop to calculate the total votes for each candidate according to the following structured english: for each array position add the element at that position in the online vote array to the element at the position in the paper vote array. store the result at the corresponding position in the total votes array end for I have been scratching my head for 3 hours now, I have to have this assignment uploaded before midnight to my tutor or I am in the poo Any help really really appreciated. Thanks in advance Similar TutorialsI am trying to split the (id) values between seperate forms and the submit buttons are not located between the form tags. Note: ->The 3 forms are located at the top of page ->the (3) Submit buttons are in a query and are outside the form tags. ->In this case it does not make sense to have the form duplicating itself in the sql_query. need the correct code for the 3 script functions var form1, form2, form3 then i need the correct function submit code something like -> onClick='Split(this.form1,1)' Also: To keep this simple could the 3 scripts be combined into one? Code: <!-- SPLIT VALUES BETWEEN SEPERATE FORMS --> <script type="text/javascript"> function Add(sel,first) { if (sel.selectedIndex == 0 ) return; var temp = sel.id.split(","); sel.form1["F"+first].value = temp[0]; sel.form1["F"+(first+1)].value = temp[1]; } </script> <script type="text/javascript"> function Edit(sel,first) { if (sel.selectedIndex == 0 ) return; var temp = sel.id.split(","); sel.form2["F"+first].value = temp[0]; sel.form2["F"+(first+1)].value = temp[1]; } </script> <script type="text/javascript"> function Delete(sel,first) { if (sel.selectedIndex == 0 ) return; var temp = sel.id.split(","); sel.form3"F"+first].value = temp[0]; sel.form3["F"+(first+1)].value = temp[1]; } </script> <form method='post' name='form1' action='record_add.php'> <input type='hidden' id='F1' name='t101' value='' > <input type='hidden' id='F2' name='t102' value='' > </form> <form method='post' name='form2' action='record_edit.php'> <input type='hidden' id='F3' name='t103' value='' > <input type='hidden' id='F4' name='t104' value='' > </form> <form method='post' name='form3' action='record_delete.php'> <input type='hidden' id='F5' name='t103' value='' > <input type='hidden' id='F6' name='t106' value='' > </form> <!-- NOTE: THE SUBMIT BUTTONS ARE IN A QUERY OUTSIDE THE FORM TAGS AND NEED TO TARGET THE PROPER FORM1,2,3 onClick --> <button type='submit' id='$mytable,$columns[Field]' onClick='Split(this.form1,1)'> <button type='submit' id='$mytable,$columns[Field]' onClick='Split(this.form2,3)'> <button type='submit' id='$mytable,$columns[Field]' onClick='Split(this.form3,5)'> I have 4 text boxes that are supposed to load 4 seperate values of data from one field in one table from a database. The field is called interface_cropsettings (from the interface table) and these values have been concatenated and comma seperated in this field. Code: <TR> <TD WIDTH="350" CLASS="tabledata"><INPUT TYPE="TEXT" SIZE="55" NAME="txtInterfaceXPosition" maxlength="10" <CFIF IsDefined("isEdit")>VALUE="#qryEditInterface.interface_cropsettings#"></CFIF></TD> </TR> <TR> <TD WIDTH="350" CLASS="tabledata"><INPUT TYPE="TEXT" SIZE="55" NAME="txtInterfaceYPosition" maxlength="10" <CFIF IsDefined("isEdit")>VALUE="#qryEditInterface.interface_cropsettings#"></CFIF></TD> </TR> <TR> <TD WIDTH="350" CLASS="tabledata"><INPUT TYPE="TEXT" SIZE="55" NAME="txtInterfaceCropHeight" maxlength="10" <CFIF IsDefined("isEdit")>VALUE="#qryEditInterface.interface_cropsettings#"></CFIF></TD> </TR> <TR> <TD WIDTH="350" CLASS="tabledata"><INPUT TYPE="TEXT" SIZE="55" NAME="txtInterfaceCropWidth" maxlength="10" <CFIF IsDefined("isEdit")>VALUE="#qryEditInterface.interface_cropsettings#"></CFIF></TD> </TR> Once the form is filled out and saved, the data is inserted into the database and the values from these 4 text boxes are concatenated, comma seperated and inserted into that one field correctly. (Example) If the 4 text boxes have the following values: X Position = 12.34 Y Position = 56.78 Crop Height = 250 Crop Width = 500 in the database field they become: 12.34,56.78,250,500 However, if the form is closed and then re-opened, each text box displays the entire database field rather then each value seperated in the corresponding text box. (Example) All 4 text boxes display this: 12.34,56.78,250,500 I already know why the data appears like this in the form, my problem is that I'm not sure how to write the javascript to seperate the values into the correct corresponding fields, assuming javascript is what I should be using! Can anyone help me out with this?? Also, this is kind of irrelevant but just in case you're wondering, this form is part of a cold fusion application! hi, I am fairly new to jquery and would like som direction on how to complete this menu. I have a list which has 6 bg images which have on and active state images. these are are currenly changing when you hover using the a:hover css. my question is i have a fairly large page and as you scroll down the menu follows the top of the screen but what i would like to happen is when the menu reaches a certain point on the page the menu item that it corrosponds to becomes active (changes to the on state bg image). i have an idea that as you scroll down the page and you get to a certain position on the page you would remove the classes for all of them. use the selecter to select my id and add a special class with that specific bg image on it. the only part i am struggling with is how would i determin how far down the page i am i know theres a function called .position() and you can use position.top. but not sure how i can use that to help me. if you could point me in the direction or just a hint that would be really helpful. thanks in advance So Im trying to make it so my button writes in one box when I click it one time, another when I click it a second, etc, but when I click it once, it writes in all boxes. Why is this? Code: content += "<br><input type='text' value='' id='d1' name='d1'><br>" content += "<input type='button' value='random card' id='r1' name='r1' onclick='randomCard()'>" content += "<div id='c1' name='c1'></div><div id='c2' name='c2'></div><div id='c3' name='c3'></div><div id='c4' name='c4'></div><div id='c5' name='c5'></div><div id='c6' name='c6'></div><div id='c7' name='c7'></div><div id='c8' name='c8'></div><div id='c9' name='c9'></div><div id='c10' name='c10'></div><div id='c11' name='c11'></div>" function checkValue(){ if (c1.innerHTML == ""){ c1.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML == ""){ c2.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML == ""){ c3.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML == ""){ c4.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML == ""){ c5.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML == ""){ c6.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML == ""){ c7.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML == ""){ c8.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML == ""){ c9.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML == ""){ c10.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML == ""){ c11.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML != ""){ alert('How in the **** did you get more than eleven cards?') } else{ } } } } } } } } } } } } } function randomCard(){ for (c=0;c<DCard.length;c++){ randCard = DCard[Math.floor(Math.random()*DCard.length)] document.getElementById('c1').value = randCard c1 = document.getElementById('c1') c2 = document.getElementById('c2') c3 = document.getElementById('c3') c4 = document.getElementById('c4') c5 = document.getElementById('c5') c6 = document.getElementById('c6') c7 = document.getElementById('c7') c8 = document.getElementById('c8') c9 = document.getElementById('c9') c10 = document.getElementById('c10') c11 = document.getElementById('c11') checkValue() } } Not my whole code, but the necessary parts. Hi, someone helped me and wrote this code for me: Code: <script> var totalWidth = 0; $("#gallery img").each(function(){ totalWidth += $(this).width(); }); alert(totalWidth); </script> it alerts the width of all my images, great! But now, I need to add onto that 20px between each image and 104px or so onto the end Then I need to be able to write it out to the style of the #content div? here's the site: http://www.jbiddulph.com/chrisbradshaw Please help?! Code: function move_user_img(str) { var step = 25; // change this to different step value switch(str) { case "down": var x = document.getElementById('imageUser').offsetTop; x = x + step; document.getElementById('imageUser').style.top = x + "px"; break; case "up": var x = document.getElementById('imageUser').offsetTop; x = x - step; document.getElementById('imageUser').style.top = x + "px"; break; case "left": var y = document.getElementById('imageUser').offsetLeft; y = y - step; document.getElementById('imageUser').style.left = y + "px"; break; case "right": var y = document.getElementById('imageUser').offsetLeft; y = y + step; document.getElementById('imageUser').style.left = y + "px"; break; } } function move_report_img(str) { var step = 25; // change this to different step value switch(str) { case "down": var x = document.getElementById('imageReport').offsetTop; x = x + step; document.getElementById('imageReport').style.top = x + "px"; break; case "up": var x = document.getElementById('imageReport').offsetTop; x = x - step; document.getElementById('imageReport').style.top = x + "px"; break; case "left": var y = document.getElementById('imageReport').offsetLeft; y = y - step; document.getElementById('imageReport').style.left = y + "px"; break; case "right": var y = document.getElementById('imageReport').offsetLeft; y = y + step; document.getElementById('imageReport').style.left = y + "px"; break; } } Code: <div id ="display" style="width:640px; height:480px; overflow:hidden;"> <div> <img src =" <?php echo UPLOADPATH . $userImage; ?> " style = "position:absolute;" id="imageUser"/> </div> <div id ="imageReport"> <img src = " <?php echo $reportImage; ?> " style = "opacity:0.25;height:700px; width:450px;" /> </div> </div> <div style="position:absolute; top:550px; left:100px;"> <p>Control User Image</p> <input type=button onClick=move_user_img('up') value='Up'> <input type=button onClick=move_user_img('left') value='Left'> <input type=button onClick=move_user_img('right') value='right'> <input type=button onClick=move_user_img('down') value='down'> </div> <div style="position:absolute; top:650px; left:100px;"> <p>Control Report Image</p> <input type=button onClick=move_report_img('up') value='Up'> <input type=button onClick=move_report_img('left') value='Left'> <input type=button onClick=move_report_img('right') value='right'> <input type=button onClick=move_report_img('down') value='down'> </div> Would this code i made <html> <head> <title>Demo</title> </head> <html> <body> <h3>Just a Demo</h3> <script type="text/javascript"> var numbers = new Array ( "1", "1", "1", "1", "1", "1" ); for ( i=1; i < numbers.length; i++ ) { alert ( numbers[i] ); } </script> </body> </html> Would that be an exmaple of arrays with elements intilized to 1(true) Hi there, I was hoping for some advice, not really answers as this is part of an assignment. What I have been given is two arrays and I need to multiply the elements in the first with the corresponding value in the second and then save the result into a third array. I am very very new to this and have tried every option i can think of to do this, I entered the result values into the third array just to check the rest of my code is right, this is the only part that has me stumped. Any tips would be hugely appreciated, thank you ) I need to loop the alphabet and numbers 0-9 to initialize a few thousand arrays. This is for my site and is truly needed. http://www.thefreemenu.com I currently have every array written out and it takes up to much space in my .js file. The majority of my variables are empty but necessary and need to be there (including empty) for my site to work properly. Question is the last part Here's where I'm at. Code: var NewVarLetterOrNum = "a"; eval("_oneofseveralnames_" + NewVarLetterOrNum + "='this part works';"); alert(_oneofseveralnames_a); This creates the variable _oneofseveralnames_a='this part works' Code: var newArrayLetterOrNum = "a"; eval("_oneofseveralnames_" + newArrayLetterOrNum + "= new Array();"); alert(_oneofseveralnames_a) This creates the Array _oneofseveralnames_a=new Array(); and all the values in the array are null, but, now a variable like _nl_a[1]='something' can be used elsewhere because the array exists. This is all that is necessary for now because I can probably set all the variables to be blank with something like Code: i=1 while(i<=20){ _oneofseveralnames_a[i]="1-20"; i++ } alert(_oneofseveralnames_[20]); So now you have what I came to understand in the first few hours. Now to the hard part : ( I can't make multiple array's dynamically. I dont' know if its because I don't understand loops or arrays or what and its very fustrating. As for any answer you might be so kind as to provide, if you could dumb it down that would be greatly appreciated. Code: var newArray =new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') i=1 while(i<=26){ eval("_nl_" + newArray[i] + "= new Array();"); i++ } alert(newArray[1]) // Is b, but alert(_nl_b) //I can't get _nl_b to exist, I tried everything including taking away the quotes around the letters in every test */ var _nl_a =new Array() var _img_a =new Array() var _h_a =new Array() var _r_a =new Array() var _m_a =new Array() var _yt_a =new Array() var _i_a =new Array() The above arrays are all the array _name_ parts I need but for example, a has 10 parts, a,p2_a,p3_a,.. p10_a. I need 10 pages for each letter of the alphabet and numbers 0-9 and a special all1, p2_all1 ... p10_all1. Overall 2200 arrays that need to be declared. Currently they are all written out. /* Code: <HTML> <HEAD> <TITLE>Listing 4.4</TITLE> <SCRIPT TYPE="text/javascript"> //DEFINE METHOD function displayInfo() { document.write("<H1>Employee Profile: " + this.data[0] + "</H1><HR /><PRE>"); document.writeln("Employee Number: " + this.data[1]); document.writeln("Social Security Number: " + this.data[2]); document.writeln("Annual Salary: " + this.data[3]); document.write("</PRE>"); } //DEFINE METHOD TO GET EMPLOYEE INFORMATION function getInfo() { var menu="0-Exit/1-Name/2-Emp. #/3-Soc. Sec. #/4-Salary"; var choice=prompt(menu,"0"); if (choice != null) { if ((choice < 0) || (choice > 4)) { alert ("Invalid choice"); this.getInfo(); } else { if (choice != "0") { this.data[choice-1]=prompt("Enter information",""); this.getInfo(); } } } } //DEFINE OBJECT function employee() { this.data = new Array(4); this.displayInfo=displayInfo; this.getInfo=getInfo; } newEmployee=new employee(); </SCRIPT> </HEAD> <BODY> <SCRIPT TYPE="text/javascript"> newEmployee.getInfo(); newEmployee.displayInfo(); </SCRIPT> </BODY> </HTML> I am currently taking a Javascript certification course, this is a exercise given (final code) I don't completely understand what is going on though, could someone explain to me Code: this.data[choice-1]=prompt("Enter information",""); that part? I don't understand why, [choice-1] I don't fully understand why an array is even needed here? First of all thank you for reading my thread and giving time to help me. Here goes my question: How to sort this array? MY PRIORITY COLORS array: ------------ green , yellow ALL COLORS array : <---- this will be your main array. ----------------------- pink , green , orange THE RESULTS: ( the results after you sort) (Not sorted by alphabetically, but sorted by the priority colors) ---------------- green , pink , orange I hope you could help me solve this javascript sorting problem. Thank you! Hi. I am fairly new to JavaScript. I am having some troubles with arrays. I am using Chrome 12 beta. Here is a brief version of the code I am having trouble with Code: var array=new Array() array[0]=new Array() array[0][1]=new Array() var array[0][1]=[ 3, 1, 4, 1, 5, 9, 2, 6, 5, ... ]; I do not want to use "array[0][1][n]" because my array has too many items to do that and it is just plain annoying to change the numbers that way. I get an error on the "var buffers[0][1]=[" line saying: "Uncaught SyntaxError: Unexpected token [" What is the problem in my code? Thank you ahead of time. ---mint Hi could someone help with this javascript. i dont know where to start with the script which is in bold. Program to report the results of an election. // candidates var candidateArray = ['Mr R Green...', 'Ms O Brown...', 'Ms Y Black...', 'Mr G White...', 'Ms B Grey....','Ms I Blue....', 'Mr V Pink....']; // online votes var onlineVotesArray = [21,47,23,11,56,47,30]; // paper votes var paperVotesArray = [12,4,20,11,5,4,17]; // total votes -- to be initialised below var totalVotesArray; // Add code to // -- initialise totalVotesArray with a new empty array of the same size as candidateArray // -- use a for loop to add the online and paper votes for each candidate and store the result at the corresponding position in the total votes array. I am working on making 2 for loops of 2 arrays to get the total of them. Then I need to get the average heights. This is for a test, yet I have not got a clue, so I need clues as I cant get it to work and I am a new coder to javascript. Code: var heights = [15,16,17,18,19]; var numbers = [2,1,6,4,2]; var average = new Array(5); average = 0 for (var heights = 0; heights <= 5; heights = heights+ 1) { total = 0 } for (var numbers = 0; numbers <= 5; numbers = numbers + 1) { total = 0 average = heights / numbers; } document.write('The average height is ' + average); Am I on the right road? I need to use this format and not functions. I have got 2 for statements but maybe I could do this with one, it is so tricky this javascript. I have a choice when creating a new API that I would like other peoples opinions on. Do I use a single Array or Multiple arrays such as: Code: array[1][1] = "ID[56]NAME[Hello World]START[10]"; OR Code: ID[1][1] = 56; Name[1][1] = "Hello World"; Start[1][1] = 20; The API is used for animations so is very heavy work, but would using around 15 multidimensional arrays be too much and a single one be preferable??? Thanks OK first of all I will post some screenshots of the 'website' I have created so far and explain what is working and what is not working. Then I will post my code and ask for help. Below is the main screen before any action happens. The three boxes are DIV elements. The writing and dropdown menu in the first box is generated by Javascript code. Whenever a user selects an option from the dropdown menu. Information about the movie and a picture of the cover are displayed. The movie title, picture filename and movie description are all stored in three separate arrays. Now for the problem. I have created a fourth array "customerList" and left it empty. Whenever a customer clicks the reserve button it calls a function "myReserve()". This function takes the selection from the dropdown menu, then uses the push function to add the selection to the blank array. I then use the code "arrayLength = customerList.length" to get the length of the customer list. A for loop is used to cycle through the array and display the contents of the array. The problem is it only displays one selection. When reserve is clicked again the newest selection is displayed. Why will it not push the next item into the array? Javascript code, just skip through the 3 arrays at the top... the problem function is at the bottom. Code: var movieTitles = new Array(8) movieTitles[0] = "The Prestige [2006]" movieTitles[1] = "The Lives of Others [2007]" movieTitles[2] = "The Bourne Ultimatum [2007]" movieTitles[3] = "Spider-Man 3 [2007]" movieTitles[4] = "Casino Royale [2006]" movieTitles[5] = "The Illusionist [2006]" movieTitles[6] = "Sunshine [2007]" movieTitles[7] = "Zodiac [2007]" movieTitles[8] = "Quantum of Solace [2008]" var movieCovers = new Array(8) movieCovers[0] = "prestige.jpg" movieCovers[1] = "lives_of_others.jpg" movieCovers[2] = "bourne3.jpg" movieCovers[3] = "spiderman3.jpg" movieCovers[4] = "casinoroyal.jpg" movieCovers[5] = "illusionist.jpg" movieCovers[6] = "sunshine.jpg" movieCovers[7] = "zodiac.jpg" movieCovers[8] = "quantum_of_solace.jpg" var movieDescriptions = new Array(8) movieDescriptions[0] = "Two Victorian-era magicians develop a rivalry that builds into an escalating battle of tricks." movieDescriptions[1] = "Five years before its downfall, the former East-German government ensured its claim to power with a ruthless system of control and surveillance." movieDescriptions[2] = "Legendary assassin Jason Bourne uncovers mysteries of his past, which puts him in the cross-hairs of a superkiller." movieDescriptions[3] = "When Peter Parker's suit suddenly turns black it brings out the dark, vengeful side of his personality." movieDescriptions[4] = "The story examines James Bond's first mission after getting his licence to kill." movieDescriptions[5] = "Eisenheim is a stage magician who amazes the audiences of turn-of-the-century Vienna, drawing the attention of Crown Prince Leopold." movieDescriptions[6] = "Fifty years from now, the sun is dying, and mankind is dying with it. Our last hope: a spaceship carrying a device which will breathe new life into the star." movieDescriptions[7] = "A serial killer terrifies the San Francisco Bay Area and taunts police with his ciphers and letters." movieDescriptions[8] = "Seeking revenge for the death of his love, secret agent James Bond sets out to stop an environmentalist from taking control of a country's water supply." var customerList = new Array() function getMovieTitle() { var str = "<p>Available movies are contained in the list below.<br />Select a movie title to read more details.<br />If you want to add the movie to your list click the reserve option.<br /></p>" str = str + "<form action='P4_1.html' method='post'><select onChange = 'displayMovie()' name='title' id = 'droplist'><option>Choose a movie</option>" mylength = movieTitles.length //loop for each movie title in the movieTitles array for (var i=0; i<mylength; i++) { str = str + "<option>" + movieTitles[i] + "</option>" } str = str+"</select></form>" //place content into dropdown menu document.getElementById("dropdown").innerHTML = str } function displayMovie() { var i i = document.getElementById('droplist').selectedIndex - 1 var m = movieTitles[i] m = m + "<p><br><img src='"+movieCovers[i]+"'></p>" m = m + movieDescriptions[i] m = m + "<p> <a href='Javascript:myReserve()'><span id = 'res'> Reserve </span></a></p>" document.getElementById("Movie_Info").innerHTML = m } function myReserve() { var i i = document.getElementById('droplist').selectedIndex - 1 customerList.push(movieTitles[i]) arrayLength = customerList.length for (var j=0; j<arrayLength; j++) { str = customerList[j] } document.getElementById("Movie_List").innerHTML = str } HTML code, incase you want to create my files yourself to troubleshoot for me but all the problems occur in the myReserve function just above. Everything else works fine. Code: <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> <head> <title>P4_1</title> <script src="P4.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" media="screen" href="P4.css" /> <!--[if gte mso 9]><xml> <mso:CustomDocumentProperties> <mso:ContentType msdt:dt="string">Document</mso:ContentType> </mso:CustomDocumentProperties> </xml><![endif]--> </head> <body onload="javascript:getMovieTitle()"> <img src="logo.jpg"> <div id="dropdown" class="box1"> </div> <div id="Movie_Info" class="box2"> <p>Movie info will go here</p> </div> <div id="Movie_List" class="box3"> <p>Your movie list will go here</p> </div> </body> </html> This has been resolved. The moment i posted it i realised the mistake i was making . Learnig how to delete my post, until then thought i would sdimply delete the content.
Hi, I am trying to merge the values of 2 arrays. array 1 = 1, 2, 3, 4, 5 array 2 = a, b, c, d, e Resulting in: array 3 = 1-a, 2-b, 3-c, 4-d, 5-e etc both arrays that will be used originally will always of the same length. Both arrays will contain numbers Can you please help? Thanks Do arrays retain its data outside of a function. The reason why i asked this is because i created a global array and then a function. In the function i assaigned values to the global array but when i try to access the global array it gives me a "undefined" or "null" error. Code: var myArray = new Array(); var count = 0; function populate(){ for(i=0; i < 5; i++){ myArray[i] = count++; } } |