JavaScript - App Crashing When I Try To Instantiate An Array
I have some java script in my vb.net application and I've been trying to figure out why my web app keeps crashing when i try to instantiate an array (i placed a comment where the app is crashing in the code below). Here's my code...
Code: function CopyItem(plyrDuplicate,copyPlyrPostback) { var plyrDuplicate = (typeof plyrDuplicate == "undefined")?'defaultValue':plyrDuplicate; var firstListBox = document.getElementById('<%= lstPlayerSelect.ClientID %>'); var secondListBox = document.getElementById('<%= lstPlayerQueue.ClientID %>'); var postBack = -1; if (copyPlyrPostback == 0){ postBack = 0; } //alert("in the function"); //alert(postBack); if (postBack == -1) { for (var i = 0; i < firstListBox.options.length; i++) { if (firstListBox.options[i].selected) { var newOption = document.createElement("option"); newOption.text = firstListBox.options[i].text; newOption.value = firstListBox.options[i].value; playerVal = newOption.value; CheckDuplicate(playerVal); var printRec = CheckDuplicate(playerVal); alert(playerVal); alert(CheckDuplicate(playerVal)); if (printRec != true) { //alert(secondListBox.options[secondListBox.options.length]); //alert(secondListBox.options.length); secondListBox.options[secondListBox.options.length] = newOption; } } } if (document.getElementById('ErrorMsg').style.display = 'inherit') { document.getElementById('ErrorMsg').style.display = 'none'; } } else { alert("inside other else block, hurray~!!!"); hdnSessionVariable = '<%=Session("playerId")%>'; hdnSessionVariable = hdnSessionVariable.split(","); for (var ii = 0; ii < hdnSessionVariable.length; ii++) { for (var i = 0; i < firstListBox.options.length; i++) { if (hdnSessionVariable[ii] == firstListBox.options[i].value) { //alert("we have a match!!!"); var newOption = document.createElement("option"); newOption.text = firstListBox.options[i].text; newOption.value = firstListBox.options[i].value; playerVal = newOption.value; CheckDuplicate(playerVal); var printRec = CheckDuplicate(playerVal); alert(playerVal); alert(CheckDuplicate(playerVal)); alert(newOption.value); if (printRec != true) { secondListBox.options[secondListBox.options.length] = newOption; //app crashes on this line } } } } Updatelist(); return false; } Hopefully the code above is enough for to figure out the issue. However, here's a mini recap of what's going on. A user selected a value from firstListBox and the function above copies it over to secondListBox. The code in the first condition works fine, but the code in the else block doesn't. Now, here's the catch/difference between the if and else statement...the Else block is basically doing the same thing as the if statement, except the values that needs to be copied are coming from a session variable (hdnSessionVariable = '<%=Session("playerId")%>'. I've commented out every line in the else statement and the app works until it hits the secondListBox.options[secondListBox.options.length] = newOption line. Anybody have any idea what's wrong here? Similar TutorialsHello there everyone! I am currently rebuilding my portfolio and utilizing lightwindow as a means to display my projects. I have set up the site so that there is a grid of thumbnail images and also a textual list of links (basically another means for the user to navigate the projects if they prefer not to use the thumbnail links). For some projects I need to use the gallery function to display multiple images. I have this functioning when you click on the thumbnail link just fine. The problem is having the corresponding text link utilize the same set of images without creating a duplicate set. Is there a way to call the gallery without putting links to each image utilizing "class" and "rel". Here is a brief section of the html to show you what I mean...I have minimized it to show you clearly what I am trying to do... Code: <!-- Text List of Links to Projects --> <div id="subNav" style="display:none;"> <ul> <li class="listHeader">Web & Interactive</li> <li> <a href="imgs/gallery/proj1.jpg" class="lightwindow" title="Dynamic Info Design" caption="A caption can go here..." >Dynamic Info Design</a> </li> </ul> </div> <!-- Thumbnail Image Links to Projects --> <div id="portfolioContent"> <div id="thumbnail"> <!-- Set of Images to be used in gallery--> <a href="imgs/gallery/projectName/proj2A.jpg" class="lightwindow" title="Dynamic Info Design" caption="A caption can go here..." rel="Web & Interactive[Dynamic Info Design]"> <img src="imgs/thumbnails/project1.jpg" alt="Project Name" /> </a> <a href="imgs/gallery/projectName/proj2B.jpg" class="lightwindow" title="Dynamic Info Design" caption="A caption can go here..." rel="Web & Interactive[Dynamic Info Design]"></a> <a href="imgs/gallery/projectName/proj2C.jpg" class="lightwindow" title="Dynamic Info Design" caption="A caption can go here..." rel="Web & Interactive[Dynamic Info Design]"></a> </div> </div> I want to call that same set of 3 images with the text link <a href="imgs/gallery/proj1.jpg" class="lightwindow" title="Dynamic Info Design" caption="A caption can go here..." >Dynamic Info Design</a> Right now it's just showing the one image...if I use the rel tag in that link, it adds the image as a duplicate and then says there are 4 images in the set instead of 3. Does this make sense to anyone. How can I pull this same gallery up without duplicating the images or having the same project show up twice when you click on the gallery tab. View actual site in progress at: http://www.reneeclements.com/newWebs...sign/index.php Any insight would be greatly appreciated! Thanks! Reply With Quote Hello, I have a website that I need help with. You can visit it he http://www.shahspace.com/bow/home.html. To see what I need help with, click on the services menu item and observe the alert message that comes up. It should say "point 1". Here is the code that executes that: Code: function enableScrolling(menuName) { alert("point 1"); var menu = document.getElemenetById(menuName); alert("point 2"); ... } As you can see, there should be a second alert message that says "point 2", but there isn't. The script is crash when I try to assign to menu the object returned by document.getElementById(menuName). I have verified that menuName is correct. So why would this be crashing? To get a fuller understanding of my algorithm, I'll give you the following: The menu div: Code: <div id="services_menu" class="services_menu"> ... </div> The "services" button: Code: <td><a href="#" onclick="displayMenu('services'); return false;"><img src="services.jpg" border=0></a></td> The displayMenu() function: Code: function displayMenu(menu) { var menuName = menu + "_menu"; document.getElementById(menuName).style.display = "block"; if (itemCount(menuName) >= 12) { enableScrolling(menuName); } else { disableScrolling(menuName); } } The itemCount() function: Code: function itemCount(menuName) { var menu = document.getElementById(menuName); var divArray = menu.getElementsByTagName("div"); return divArray.length; } And the enableScrolling() function I already posted above. So essentially, when the user clicks on "service", the services menu becomes visible. If the menu contains 12 items or more, scrolling needs to be enabled. This entails setting the menu to a fixed height and allowing the user to scroll through it (scrolling, in this case, will be customized--I'm not using the div's native scrolling feature). The really odd thing is that in itemCount(), I have exactly the same line: var menu = document.getElementById(menuName); and it works fine there. Why not in my enableScrolling() function? Hello all. I'm working on a photo upload script. All works well until I added a simple script to get the document body innerHTML so that I could report back to the user if there was any errors or not. So... Code: addEvent($('uploaderIframe'),"load",showLoad); } var showLoad = function() { removeEvent($('uploaderIframe'),"load",showLoad); $('uploaderIframe').src="javascript:window.parent.document.getElementById('uploadInfo').innerHTML = document.body.innerHTML;"; } } It seems that whenever I try to change src of the iframe it crashes. Not to sure why, as I've seen this be done on other Ajax like Photo upload scripts. Can I get some help with this please... Here's the full script: Code: function addEvent(obj, evType, fn){ if(obj.addEventListener) obj.addEventListener(evType, fn, true) if(obj.attachEvent) obj.attachEvent("on"+evType, fn) } function removeEvent(obj, type, fn){ if(obj.detachEvent){ obj.detachEvent('on'+type, fn); }else{ obj.removeEventListener(type, fn, false); } } function ajaxPhotoUploader() { document.getElementById('file_upload_form').onsubmit=function() { if($('uploaderIframe')) { document.getElementById('file_upload_form').removeChild(document.getElementById('uploaderIframe')); } $('uploadInfo').innerHTML = '<img src="./images/ajax-loader.gif" />'; if(window.ActiveXObject) { var iframe = document.createElement("<iframe id=\"uploaderIframe\" name=\"uploaderIframe\" src=\"./uploadto.php\" style=\"width:200px;height:200px;\">"); } else { var iframe = document.createElement("iframe"); iframe.setAttribute("name","uploaderIframe"); iframe.setAttribute("src","./uploadto.php"); iframe.setAttribute("id","uploaderIframe"); } document.getElementById('file_upload_form').appendChild(iframe); document.getElementById('file_upload_form').target = 'uploaderIframe'; //'uploaderIframe' is the name of the iframe addEvent($('uploaderIframe'),"load",showLoad); } var showLoad = function() { removeEvent($('uploaderIframe'),"load",showLoad); $('uploaderIframe').src="javascript:window.parent.document.getElementById('uploadInfo').innerHTML = document.body.innerHTML;"; } } Thanks, Jon W Hello again , I have another question, I am trying to make a javascript timer that times in tenths of seconds (eg. 1.6 seconds). I have made what I believe to be suitable code but I think that it can't be very effiecient as the code won't run because the browser crashes. Here is the code: Code: function seconds() { while (timergoing=1) { tenthseconds=tenthseconds+1; if (tenthseconds=10) { tenthseconds=0; seconds=seconds+1; } } } function timer() { timergoing=1; tenthseconds=0; seconds=0; setInterval('seconds()', 100); while (timergoing=1) { document.getElementById('timeis').innerHTML = seconds + '.' + tenthseconds + 'seconds'; } } And for the HTML: Code: <button type="button" onclick="timer()">Start</button> <br><br> <div id="timeis"></div> I am working on a page where the user will select a location from a dynamically generated dropdown list. I was able to create the php multidimensional array (tested and working) from a MySql database using the users information at login, but I'm having problems converting it to a javascript multidimensional array. I need to be able to access variables that I can pass to a number of text fields within an html form. For instance, if a user belongs to a company with multiple addresses, I need to be able to let them select the address they need to prepopulate specific text fields. php array creation: Code: if ($row_locations) { while ($row_locations = mysql_fetch_assoc($locations)) { $mail[$row_locations['comp_id']]=array('mailto'=>$row_locations['mailto'], 'madd'=>$row_locations['madd'], 'madd2'=>$row_locations['madd2'], 'mcity'=>$row_locations['mcity'], 'mstate'=>$row_locations['mstate'], 'mzip'=>$row_locations['mzip'], 'billto'=>$row_locations['billto'], 'badd'=>$row_locations['badd'], 'badd2'=>$row_locations['badd2'], 'bcity'=>$row_locations['bcity'], 'bstate'=>$row_locations['bstate'], 'bzip'=>$row_locations['bzip']); } } javascript function - this should create the array and send variables to text fields. Code: function updateAddress() { var mail = $.parseJSON(<?php print json_encode(json_encode($mail)); ?>); { if (comp_id in mail) { document.getElementById('mailto').value=mail.comp_id.mailto.value; document.getElementById('madd').value=mail.comp_id.madd.value; document.getElementById('madd2').value=mail.comp_id.madd2.value; document.getElementById('mcity').value=mail.comp_id.mcity.value; document.getElementById('mstate').value=mail.comp_id.mstate.value; document.getElementById('mzip').value=mail.comp_id.mzip.value; } else { document.getElementById('mailto').value=''; document.getElementById('madd').value=''; document.getElementById('madd2').value=''; document.getElementById('mcity').value=''; document.getElementById('mstate').value=''; document.getElementById('mzip').value=''; } } } Where is this breaking? Thanks in advance. I can't seem to figure out how to accomplish this. In my website, I would like the user to input text into a single or multiple textbox(es) and then have the contents of the textbox(es) stored to either a variable or an array. Then I would like to have that variable/array compared to other arrays. Basically, the user is searching for items in a database. The user can search for as many or as little items as they want. Then the item(s) will be compared to multiple arrays to find out if what the user wants is in the database. So for example, let's say the user is searching for recipes that have all or part of these ingredients: chicken, broccoli, lemon, honey. So, there would have been a total of 4 textboxes...one for each ingredient. These ingredients are stored to an array..lets call it ingredient(). In the database of recipes, each recipe has its own array which includes the ingredients needed to make the recipe, we'll call them tag1(), tag2(), and tag3(). Now, I want the array, ingredient(), to be compared to each of the "tag" arrays to see if any of the "tag" arrays include exactly match the ingredient() tag in part or in whole. Is this possible? I have the following array that contain the people who are on off on certain time: Code: var all = [ ["1234", "Jim", "2011-10-23 00:00:00", "2011-10-25 07:00:00"], ["1235", "Jack", "2011-10-21 00:00:00", "2011-10-21 08:00:00"], ["1236", "Jane", "2011-10-11 00:00:00", "2011-10-11 00:30:00"], ["1237", "June", "2011-10-20 00:00:00", "2011-10-20 12:00:00"], ["1238", "Jill", "2011-10-14 00:00:00", "2011-10-14 11:00:00"], ["1239", "John", "2011-10-16 00:00:00", "2011-10-16 10:30:00"], ["1240", "Jacab", "2011-10-19 00:00:00", "2011-10-20 08:30:00"] ]; The above array, I wish to use javascript to insert into the FullCalendar (http://arshaw.com/fullcalendar/). I notice that the only way seems to be using the FullCalendar array style (or structure) as follows: Code: $('#calendar').fullCalendar({ events: [ { title : 'event1', start : '2010-01-01' }, { title : 'event2', start : '2010-01-05', end : '2010-01-07' }, { title : 'event3', start : '2010-01-09 12:30:00', allDay : false // will make the time show } ] }); So, the question is: How do I insert my array to match with the FullCalendar array? cause FullCalendar array had a different array structure from my array - and I don't think so that I can write in this way: Code: $('#calendar').fullCalendar({ events:all }); Appreciate any help provided. Hey guys, I'm hoping this is possible or that there is an easier way to do this. I'm having an issue with displaying data from one array that contains information about users in a table that is controlled by a different array. Is it possible to do this or is this use of arrays to display the data the wrong approach? The table is located on one webpage, I simply want to extract one piece of information that I have placed in the initial array as part of the login script that contains user information (for validation for login etc) and display it in a table on the new webpage that is opened as a result of successful validation of the user details. I'm completely stumped and after many attempts I just can't seem to get it to work. Hi, Here is a working code to copy 2d php array to 2d javascript array. Code: <html> <head> <?php for($i = 0; $i < 3; $i++) { for($j = 0; $j < 2; $j++) {$quest[$i][$j] = $i*10+$j;} } ?> <script type="text/javascript"> var questions = new Array(3); for (var i = 0; i < 3; i++) { questions[i] = new Array(2); } questions[0] = ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"", $quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"", $quest[2]); ?>"]; document.write(questions[0][0] + "<br />"); document.write(questions[0][1] + "<br />"); document.write(questions[1][0] + "<br />"); document.write(questions[1][1] + "<br />"); document.write(questions[2][0] + "<br />"); document.write(questions[2][1] + "<br />"); </script> </head> </html> Now,here's the thing.Notice these lines in the code questions[0] = ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"", $quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"", $quest[2]); ?>"]; I would like to put these lines in a loop,something like for (var i = 0; i < 3; i++) { questions[i] = ["<?php echo join("\", \"", $quest[i]); ?>"]; } But even after a lot of efforts I am unable to do so,what am I doing wrong?Thanks Hi, In a nutshell,can anyone tell me how to copy a 2d (two dimensional ,2 dimensional) php array to 2d javascript array?I would be obliged if anyone can provide me a method of doing that OR I have written a code to copy a 2d php array to a 2d javascript array.It is working but there is one problem(please see the following).Can anyone tell me what I am doing wrong here? The 2d php array is $quest[100][6] and the 2d javascript array is questions[100][6] . I have written the javascript code inside the <?php....?> itself using echo "<script language="javascript" type="text/javascript">.......</script>; Now ,inside the javascript,when I try to copy the 2d php array to the 2d javascript array using the following method it works questions[0]= ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1]= ["<?php echo join("\", \"", $quest[1]); ?>"]; ... and so on However, if I try to do the same using the following method it does not work for (var i= 0; i <= 99; i++) { questions[i]= ["<?php echo join("\", \"", $quest[i]); ?>"]; } Why is that?What mistake am I making?Any help will be deeply appreciated.Thanks -----------------------------THE CODE------------------------------------ <?php Access database and store result of mysq_query in $result....... $result = mysql_query($query); for ( $count = 0; $count <= 99; $count++) { $quest[$count]=mysql_fetch_array($result,MYSQL_NUM);; } echo "<script language="javascript" type="text/javascript"> var questions = new Array(100); for (var i = 0; i <100; i++) { questions[i] = new Array(6); } /*The following method of copying 2d php array to 2d javascript array is not working for ( var i = 0; i <= 99; i++) { questions[i]= ["<?php echo join("\", \"", $quest[i]); ?>"]; } */ /*The following method ,however,is working*/ questions[0]= ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"",$quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"",$quest[2]); ?>"]; ....and so on </script>"; mysql_close($db_server); ?> Hi, i can't find the mistake in my little script hope someone can help me. PHP Code: <?php /* -------------------- read thumbfolder -------------------- */ function isRdyPfD($filename){ if ($filename == '.' || $filename == '..') { // To-Top-Dir return false; } $ext = explode(".",$filename); $ext = $ext[sizeof($ext) - 1]; $allowedformats = array ( 'jpg', 'png', 'jpeg', 'gif' ); return in_array($ext,$allowedformats); } function getPicsfromDir($dir){ /* array with names of the pictures in $dir */ if (is_dir($dir)) { if ($dh = opendir($dir)) { $filearray = array(); while (($file = readdir($dh)) !== false) { if (isRdyPfD($file) === true) { $filearray[] = $file; } } closedir($dh); return $filearray; } } else { return false; } } // End Function $thumbs = getPicsfromDir("./images/thumbs/"); /* -------------------- thumbfolder -------------------- */ echo "<div id='thumbslider'>\n"; echo "<ul id='thumbs'>\n"; for($i = 0; $i < count($thumbs); $i++){ echo "<li><img src=\"./images/thumbs/$thumbs[$i]\" onclick=\"thumbClick($i)\" /></li>\n"; } echo "</ul>\n"; echo "</div>\n"; /* -------------------- big size images folder -------------------- */ $bigSizeImages = getPicsfromDir("./images/"); //print_r($bigSizeImages); $jsValue = ''; for ($j=0; $j < count($bigSizeImages); $j++){ $jsValue = $jsValue . $bigSizeImages[$j]; if ($j < (count($bigSizeImages)-1)) { $jsValue = $jsValue . ","; } } ?> <script type="text/javascript"> images = new Array(<?php echo $jsValue ?>); function thumbClick(pos){ //alert(pos); alert(images[pos]); } </script> I can't trace the images array values? thanks for a feedback!!! I'm having major pains trying to figure this out. I'm kind of new to Javascript, I need to open a text file from an external server, store each line in an array, then search that array for a certain word (HIGH), and if it exists then write something to the webpage, and if not, write something else. Here is what I have so far: Code: <html> <head> <title>Test</title> <script> <!-- function test(x) { if (wxd1txt.readyState === 4 && wxd1txt.status === 200) { // Makes sure the document is ready to parse and Makes sure it's found the file. var wxd1text = wxd1txt.responseText; var wxd1array = wxd1txt.responseText.split("\n"); // Will separate each line into an array var wxd1high = wxd1array.toString(); //Converting the String content to String //var highsearchreg = new RegExp("HIGH"); //var wxd1high = wxd1array[x].search(highsearchreg); document.write(wxd1high); if (wxd1high.search("HIGH") >= 0){ document.write("HIGH RISK");} else { document.write("NO RISK");} } } //--> </script> </head> <body> Hi! <script> <!-- var Today = new Date(); var ThisDay = Today.getDate(); var ThisMonth = Today.getMonth()+1; var ThisYear = Today.getYear(); var Hour = Today.getHours(); var Day2 = Today.getDate()+1; var Day3 = Today.getDate()+2; if (navigator.appName != "Microsoft Internet Explorer") { ThisYear = ThisYear + 1900;} if (ThisMonth < 10) { ThisMonth = "0" + ThisMonth;} if (ThisDay < 10) { ThisDay = "0" + ThisDay;} if (Hour == 2 || Hour == 22 || Hour == 23 || Hour == 0 || Hour == 1) { var wxHourd1 = 0600} else if (Hour >= 3 && Hour <= 10) { var wxHourd1 = 1300;} else if (Hour >= 11 && Hour <= 13) { var wxHourd1 = 1630;} else if (Hour >= 14 && Hour <= 16) { var wxHourd1 = 2000;} else if (Hour >= 17 && Hour <= 21) { var wxHourd1 = 0100;} //var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/"+ThisYear+"/KWNSPTSDY1_"+ThisYear+""+ThisMonth+""+ThisDay+""+wxHourd1+".txt"; var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/2010/KWNSPTSDY1_201005101300.txt" //(High risk day for testing) //document.write(wxurld1); //Use this to verify this section is working if (window.XMLHttpRequest) { wxd1txt=new XMLHttpRequest(); } else // IE 5/6 { wxd1txt=new ActiveXObject("Microsoft.XMLHTTP"); } wxd1txt.open("GET", wxurld1, true); wxd1txt.onreadystatechange = test(); // --> </script> </body> </html> When added to a webpage, nothing shows up except the "Hi!" and there are no errors in the Javascript Console in Google Chrome. Is this possible with Javascript, and if so, what am I doing wrong or not doing? Also, I have 2 URLs, one is a text file that has the HIGH text I want for an example, the other is the current file, which shouldn't have HIGH in it (unless the weather in the US turns really bad) Hello I'm have some javascript objects with arrays that should be transferred as php array. Its posted by ajax httpRequest. How can I return php array, from the javascript? JS Code: ['asd1', 'asd2', 'asd3'] via Ajax => PHP PHP Code: array('asd1', 'asd2', 'asd3'); Hi, i have an input value array for customer ids, i also need to make a copy of that array into another input element on submit to use for another process. So far here is what i have come up with regarding the js the current html is this Code: <!-- original input --> <input id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $commissions[$i]['id'];?>" onclick="isChecked(this.checked);" type="checkbox" /> <!-- this is new html input which is outside the $i loop that i need a copy of cid[] stored on submit <input type="hidden" name="ids[]" onsubmit="valueTovalue();" /> <!-- here is the js so far --> <script type="text/javascript"> function valueTovalue() { var valin = document.adminForm.cid.value; //cid is the array cid[] document.adminForm.ids.value = valin; //copy the array to the new input element array ids } </script> so basically if they click 1 cid then ids will also show 1, if they click all cid then ids will show all as well. will that work the way i have it, am i even close here.. thanks update: what i have seems to work fine for text values or string values but not for arrays, what am i missing that it wont copy an array? Array ( [cid] => Array ( [0] => 1 ) [task] => remarksonly [remark] => hhhyyy [boxchecked] => 1 [ids] => Array ( [0] => ) ) am i getting closer lol Code: function valueTovalue() { var valin = cid.concat; document.adminForm.ids.value = valin.concat; return(true); this has to be close i hope Code: document.adminForm.ids.value = [].concat(document.adminForm.cid); Code: <html> <head> <script type="text/javascript"> <!--- var Jane=new Array ("Female","Red","Lipstick","28",","45789546"); var Mary=new Array ("Female","Orange","Lipstick","25",","45789547"); var Elle=new Array ("Female","Blue","Lipstick","21",","45789548"); document.write(Jane[0]); document.write(Jane[1]); document.write(Jane[2]); document.write(Jane[3]); document.write(Jane[4]); //--> </script> <html> Please help me with the above code. I would like to have a prompt so I can enter one of the three girls name (array) then it would display all the elements. For example: Enter a name: Jane the output would be : Female Red Lipstick 28 45789546 Please help. Thank you very much. Im trying to create a 2d array with these two rows - Example1, Example2, Example3 Example4, Example5, Example6 To print I use this for loop- Code: for(i = 0; i < 2; i++) { for( j = 0 ; j < 3; j++) { document.write(array[i][j]); } } I dont Understand how to create the actual 2d array though. Can someone please shed some light on the situation. Thanks alot I'm calling a function that I want to loop thru an array, check the values and disable the drop down accordingly. Code: function toggleSelect() { var selBox = new Array(4); selBox[0] = document.getElementById('wcsave_10_session_mconc1'); selBox[1] = document.getElementById('wcsave_10_session_mconc2'); selBox[2]= document.getElementById('wcsave_10_session_aconc1'); selBox[3] = document.getElementById('wcsave_10_session_aconc2'); for (var i = 0; i < selBox.length; i++){ if (selBox[i].selectedIndex !=0 ) {selBox[i].disabled = true;} else {selBox[i].disabled = false;} } } and here's the rest of the code: Code: <tr valign="top"> <th>Session:</th> <td width="2"><img src="/images/star.gif" alt="required" /></td> <td width="70%"> <table border="0" cellspacing="0" cellpadding="2"> <tr valign="top"> <td align="right">Morning:</td> <td><select name="wcsave_09_msession" id="wcsave_09_msession" size="1" onblur="CheckField(this.form,this,'');" onchange="display1(this,'Mastery sesson 1','Concurrent sessons 1-6');toggleSelect();"> <option value="" selected="selected">Choose one</option> <option value="Mastery sesson 1">Mastery sesson #1</option> <option value="Concurrent sessons 1-6">Concurrent sessons #1-#6</option> </select> </td> </tr> <tr valign="top"> <td> </td> <td> <div id="Mastery sesson 1" style="display: none;"> <table class="special"> <tr valign="top"> <th width="30%"> </th> <td width="2"> </td> <td width="70%">(9:15 a.m. - 10:15 a.m.)<br /><select name="wcsave_10_session_mmastery" id="wcsave_10_session_mmastery"> <option value="" selected="selected">Choose one</option> <option value="Mastery session #1 - Computer Lab: Searching Essentials"><strong>Mastery session #1</strong> - Computer Lab: Searching Essentials</option> </select> </td> </tr> </table> </div> <div id="Concurrent sessons 1-6" style="display: none;"> <table class="special"> <tr valign="top"> <th width="30%"> </th> <td width="2"> </td> <td width="70%">Choose a session for each time slot.<br /> (9:15 a.m. - 10:15 a.m.)<br /><select name="wcsave_10_session_mconc1" id="wcsave_10_session_mconc1"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session #1 - IRB 101 for Research Nurses">Concurrent session #1 - IRB 101 for Research Nurses</option> <option value="Concurrent session #2 - A Research Poster Contest as a Tool to Learn About Research/EBP">Concurrent session #2 - A Research Poster Contest as a Tool to Learn About Research/EBP</option> <option value="Concurrent session #3 - Beginning the EBP Journey: Evaluating and Synthesizing the Literature">Concurrent session #3 - Beginning the EBP Journey: Evaluating and Synthesizing the Literature</option> </select> </td> </tr> <tr valign="top"> <th width="30%"> </th> <td width="2"> </td> <td width="70%">(10:30 a.m. - 11:30 a.m.)<br /><select name="wcsave_10_session_mconc2" id="wcsave_10_session_mconc2"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session #4 - IRB 101 for Research Nurses">Concurrent session #4 - Making Sense of Statistics When Reading Research</option> <option value="Concurrent session #5 - Original Research Presentations">Concurrent session #5 - <em>Original Research Presentations</em></option> <option value="Concurrent session #6 - IRB Considerations with Vulnerable Populations">Concurrent session #6 - IRB Considerations with Vulnerable Populations</option> </select> </td> </tr> </table> </div> </td> </tr> <tr valign="top"> <td align="right">Afternoon:</td> <td><select name="wcsave_09_asession" id="wcsave_09_asession" size="1" onblur="CheckField(this.form,this,'');" onchange="display2(this,'Mastery sesson 2','Concurrent sessons 7-12');toggleSelect();"><!--showDiv(this.value)--> <option value="" selected="selected">Choose one</option> <option value="Mastery sesson 2">Mastery sesson #2</option> <option value="Concurrent sessons 7-12">Concurrent sessons #7-#12</option> </select> </td> </tr> <tr valign="top"> <td> </td> <td> <div id="Mastery sesson 2" style="display: none;"> <table border="0" cellpadding="0" cellspacing="0" width="96%" align="center"> <tr valign="top"> <th width="30%"> </th> <td width="2"> </td> <td width="70%">(1:45 p.m. - 4:00 p.m.)<br /><select name="wcsave_10_session_mmastery" id="wcsave_10_session_mmastery"> <option value="" selected="selected">Choose one</option> <option value="Mastery session #2 - Beyond the Basics of Searching!"><strong>Mastery session #2</strong> - Beyond the Basics of Searching!</option> </select> </td> </tr> </table> </div> <div id="Concurrent sessons 7-12" class="hiddenDiv"> <table border="0" cellpadding="0" cellspacing="0" width="96%" align="center"> <tr valign="top"> <th width="30%"> </th> <td width="2"> </td> <td width="70%">Choose a session for each time slot.<br /> (1:45 p.m. - 4:00 p.m.)<br /><select name="wcsave_10_session_mconc1" id="wcsave_10_session_mconc1"> <option value="" selected="selected">Choose one</option> <option value="" selected="selected">Choose one</option> <option value="Concurrent session #7 - EBP Protocols">Concurrent session #7 - EBP Protocols</option> <option value="Concurrent session #8 - Writing for Publication">Concurrent session #8 - Writing for Publication</option> <option value="Concurrent session #9 - Original Research Presentations">Concurrent session #9 - Original Research Presentations</option> </select> </td> </tr> <tr valign="top"> <th width="30%"> </th> <td width="2"> </td> <td width="70%">(3:00 p.m. - 4:00 p.m.)<br /><select name="wcsave_10_session_aconc2" id="wcsave_10_session_aconc2"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session #10 - Writing a Research Question Using PICO">Concurrent session #10 - Writing a Research Question Using PICO</option> <option value="Concurrent session #11 - EBP Project Presentations">Concurrent session #11 - EBP Project Presentations</option> <option value="Concurrent session #12 - The Role of the Research Facilitator">Concurrent session #12 - The Role of the Research Facilitators</option> </select> </td> </tr> </table> </div> </td> </tr> </table> </td> </tr> I keep getting a selBox[i] not defined. Is it the xxx[x] = ? Sorry if this question sounds dumb but I'm a JS noob. Basically I need to create a script that will take three numerical grades entered from a prompt, as well as the student's fictitious name; then take the average of the highest and lowest grades. So far I've gotten it to: Accept then display the student's name Take three grades then figure out and display the average of all three. I still need it to: Calculate and Display the average of the highest and lowest scores Display all three scores that were entered I assume that I'll have to instantiate an array, then input values from the prompt, but everything I have tried has failed. See my script below. <script type = "text/javascript"> <!-- var gradeCounter, gradeValue, total, average, linebreak = "<br />", name, grade; total = 0; gradeCounter = 0; name = window.prompt("Input Student Name") grade = window.prompt( "Input Numerical Grade, -1 to Quit:", "0" ); gradeValue = parseInt( grade ); while ( gradeValue != -1 ) { total = total + gradeValue; gradeCounter = gradeCounter + 1; grade = window.prompt("Input Grade, -1 to Quit:", "0"); gradeValue = parseInt( grade ); } if ( gradeCounter != 0 ) { average = total / gradeCounter; document.write(name) document.write(linebreak) document.write("Average: " + average); } else document.write( "<p>No grades were entered</p>" ); // --> </script> Hi, I want to create a javascript array from a php array. At the moment, when my page loads, is loads a file called sso.js, which contains the following js array: var customarray=new Array('Bournemouth University', 'Cambridge Imaging Systems (CIS)', 'Glasgow Metropolitan College', 'Royal Holloway, University of London', 'University of Portsmouth', 'University of Brighton', 'Esher College', 'Canterbury Christ Church University', 'British Universities Film and Video Council (BUFVC)', 'Eduserv'); What I want to happen is that this array is created from a php string/ sql database. At the moment I have created a php string which has all the values in the array. Ie: <?echo $entityIDstring;?> Outputs 'Bournemouth University', 'Cambridge Imaging Systems (CIS)', 'Glasgow Metropolitan College', 'Royal Holloway, University of London', 'University of Portsmouth', 'University of Brighton', 'Esher College', 'Canterbury Christ Church University', 'British Universities Film and Video Council (BUFVC)', 'Eduserv' How can I put $entityIDstring into the javascript customarray automatically? I tried using: <input type="hidden" name="entityIDstring" id='entityIDstring' value="<?=$entityIDstring?>"/> In the page but when I tried: var customarray2 = document.getElementById('entityIDstring'); alert(customarray2.value); In the js, nothing happens. I'm trying to find Array's with the Cities of U.S. States (respectively) built. I.E. Alabama - Abbeville Abel Abernant Acmar Adamsville etc....for all 50 states. Does such an Array already exist? this might be PHP as well, so I apologize if this isn't the proper location to post just such things. |