JavaScript - Javascript If Value Exists In Array Help!
hi..
I want to have a list of words (in an array or whatever just to work) if the user put that word in a textfield (onblur or onchange) a message popup (alert) appears. (Must be popup alert) but I dont know to code it. HELP! ex.: Code: function badwords() { var badwords = new Array(); badwords =["badwords1","badwords2","AndSo-On"]; if badwords if written in textfield alert("Badwords not allowed"); else nothing happen just continue with next textfield } <input type="text" name="" onBlur=badwords()> Anyone please help Similar TutorialsI'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 am looking for a way to tell from javascript if a file exists (on the server). I don't mind doing this with a .php script, if I have to, but the javascript still needs to know if the file exists. I thought the following javascript code might work: Code: var file_exists = <?php echo file_exists("OpenTokSessionId.txt"); ?>; but it didn't. PHP parsed the php code, but it didn't assign the result value to the Javascript variable like its supposed to (or at least, it didn't seem to). When I looked at the page source after I uploaded it to the server, that line of code now looked like this: Code: var file_exists = ; Note that my server is setup to pass files with an .html or .htm extension to the php engine. That is why this kind of stuff can be done. But for some reason, php doesn't seem to be able to output bool values. I tried the following .php script, which I loaded directly in my browser, but it didn't output anything: PHP Code: <?php function fileExists() { return file_exists("OpenTokSessionId.txt")) } echo fileExists(); ?> So I changed it to the following, and it outputted "File does not exist.", which is the expected result: PHP Code: <?php function fileExists() { if (file_exists("OpenTokSessionId.txt")) echo "File exists."; else echo "File does not exist."; } fileExists(); ?> Hai Forum, May be this question is not in correct format, I want to know about how to check a particular file is exists or not ? using Javascript.One thing without using ActiveXObject because it is supports in IE only. Thanking You, Santosh Srinivas.G $_SESSION['order']['paymentmethod'] equals "Cheque". With the code bellow, I was expecting JavaScript to change the SELECT drop down menu to "Cheque", but it doesn't... However, when I remove the OPTION attribute value="cheque/", it works. This appears to be because there is a conflict with the OPTION attribute value and the SELECT content value "Cheque". Does anyone know how I can get around this issue? Code: <FORM action="" method="post" name="form"> <DIV> <SELECT class="verdana" name="paymentmethod" onchange="this.form.action = this.value;"> <OPTION></OPTION> <OPTION value="cheque/">Cheque</OPTION> <OPTION value="visa/">Visa</OPTION> </SELECT> <BR> <BR> <INPUT type="submit" value="PROCEED"> </DIV> </FORM> <SCRIPT type="text/javascript"> document.forms["form"]["paymentmethod"].value = "<?php echo $_SESSION['order']['paymentmethod']; ?>"; </SCRIPT> Hi All, I am not an expert in Javascript. Can I detect if 1 or more sessions of a website are open? for example, if a session with port 7005 is open like this one below, then I want to assign the next port to this user in the second window of browser http://90.97.8.0:7005/maximo/webclient/login/login.jsp the next IE window should appear like this: http://90.97.8.0:7006/maximo/webclient/login/login.jsp or http://90.97.8.0:7007/maximo/webclient/login/login.jsp Please advise. Thanks Yasar Hi there, I am trying to pick the larger of 5 numbers and sometimes there is a tie. I would like to prioritize variable c1 if there is a tie. This data is from a quiz I am writing. var c1 = 2; // Takes priority if there is a tie. var c2 = 1; var c3 = 2; var c4 = 0; var c5 = 0; 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. 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, 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!!! 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); ?> 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'); Hello hello, I have a javascript array to load a different picture each time a page loads up. The code is as follows: <script type="text/javascript"> var imageArray = new Array(); imageArray[0] = "images/animation9.gif"; imageArray[1] = "images/Title2.gif"; imageArray[2] = "images/animation4.gif"; function doIt() { var rand = Math.floor(Math.random()*3); var imgPath = "<img src='"+imageArray[rand]+"' alt='Welcome' border='0' align='absmiddle' />"; document.getElementById("image").innerHTML = imgPath; } </script> So...it works fine with .gifs, but how would I get it to work with .swf movies too? I've tried just putting the .swf in there e.g. ... 'imageArray[2] = "images/animation6.swf"; But that doesn't seem to work. Any ideas? Thank-you SO much in advance. Hi, Can anyone help me with this question? I have a JavaScript page to place a track to a google maps. I want the array of points to be shown to come from PHP. However, there are (probably a lot) of errors in it that makes it doesn't work. My main page code: xmlhttpT=new XMLHttpRequest(); //var MyRouteC = ""; xmlhttpT.open("GET","getRoute.php",true); //var MyRouteC= (array)xmlhttpT.responseText; var MyRouteC = (array)xmlhttpT.responseText); xmlhttpT.onreadystatechange=function() { if (xmlhttpT.readyState==4) { //MyRouteC = xmlhttpT.responseText; alert(xmlhttpT.responseText); } } xmlhttp.send(); var MyRoute = new google.maps.Polyline({ path: MyRouteC, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 }); MyRoute.setMap(map); The page it is calling is a php page: PHP Code: <?php $con = mysql_connect("xxxxx.mysql","xxxxxxxxxxx","xxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("letsmeet_mobi", $con); $query = "SELECT * FROM CurrentLocation ORDER BY time DESC LIMIT 0 , 5"; mysql_query($query); $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $output = $output . " new google.maps.LatLng(".$row['gpslat'].", ".$row['gpslong']."), "; } echo $output; mysql_close($con); ?> The php data connection works fine, and it results in a string that looks exactly like the way I want the value to be passed to the JavaScript. Any help is welcome! Hi guys, I am new to JavaScript and was wonder how I would go about creating a form to allow the user to enter various words, one at a time. These words are added to an array and displayed in the page using the textarea form element. Each time a new word is entered, it is added to the array, and then the array is sorted in alphabetical order before the words in the array are displayed in the textarea, one per line. I have tried lots and lots of different methods to accomplish this, and I can get it half working when I use the alert function, but I need this to display on the page in a textarea rather than in an alert box, I tried to get it to write to the page using a document.write function, but like I said i am new to JavaScript and unfortunately cant get any of it working. Code: Code: <!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"> <head> <title>JavaScript Page One</title> </head> <BODY> <CENTER> <FORM name="history"> <INPUT name="command" type="text" value=""> <INPUT type="button" value="Add to List" onclick="f_store(document.history.command.value)"> <INPUT name="history" type="button" value="Show List" onclick="f_print()"> </FORM> <P> <SCRIPT language="JavaScript"> function MakeArray( n ) { if( n <= 0 ) { this.length = 0; return this; } this.length = n; for( var i = 1; i <= n; i++ ) { this[ i ] = 0; } return this; } var history = new MakeArray( 15 ); var index = 0; var cmmnd = 1; function f_store( sTR ) { var i; if( index >= history.length ) { for( i = 1; i < history.length; i++ ) history[i-1] = history[i]; index = history.length - 1; } history[ index ] = cmmnd + ":" + sTR; ++cmmnd; ++index; document.history.command.value=""; } function f_print() { var allCmmnds, i; allCmmnds = ""; for( i = 0; i < index; i++ ) allCmmnds += history[i] + "\n"; alert( allCmmnds ); } </SCRIPT> </body> </html> If someone could please help me by posting some relevant code that would accomplish this, I would greatly appreciate it, as so far I have been scratching my head for a few hours. Thanks, ~Savage PLEASE help me with this I have no hair left! Thanks a million, RHonda <!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"> #container { background-color:#FFFF99; width:90%; } #header { background-color: #FFFF99; } #topNav { background-color: #FFFF99; } #content { background-color: #FFFF99; width:70%; float:left; } #displayCart { background-color:#9CC; width:28%; float:right; } #footer { background-color: #FFFF99; clear:both; } </style> </head> <body> <div id="container"> <div id="header"> <h2 align="center">WDV221 Project 11 </h2> <h2 align="center">Arrays Part 3</h2> </div> <div id="topNav"> <div align="center"> <table width="80%" border="0"> <tr> <td>Home</td> <td>Products</td> <td>Services</td> <td>About</td> </tr> </table> </div> </div> <div id="content"> <div align="center"> <h3>Available Product Selection </h3> <table width="80%" border="0"> <tr> <td><div align="center">Pencils</div></td> <td><div align="center">Pens</div></td> <td><div align="center">Scissors</div></td> <td><div align="center">Markers</div></td> <td><div align="center">Stapler</div></td> <td><div align="center">Coffee Cup</div></td> </tr> <tr> <td><div align="center">$.45</div></td> <td><div align="center">$1.19</div></td> <td><div align="center">$8.95</div></td> <td><div align="center">$4.88</div></td> <td><div align="center">$12.97</div></td> <td><div align="center">$3.00</div></td> </tr> <tr> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> </tr> </table> <p><input name="" type="button" value="Display Cart" /></p> <p><input name="" type="button" value="Remove Item From Cart" /></p> </div> <h2>Instructions</h2> <p> This project will build a Javascript base shopping cart. The scripts will add product and price to a pair of parallel arrays. It will allow the user to view the shopping cart elements, shopping cart totals and remove elements from the shopping cart. </p> <p>For purposes of this exercise we will limit the shopping cart to a maximum of 5 items. Once it has reached five items the Add a Product function will no longer allow you to add products. </p> <ol> <li>Create two parallel arrays called productName productPrice. The arrays<br /> should only allow for five rows. <br /> <br /> </li> <li>Build a function that will add the product name and product price to a row in their respective arrays. This function will activate on the Add to Cart buttons.<br /> <br /> <strong>Note</strong>: This is a great opportunity to make this a generic function and pass the product name and price into the function as parameters. The<br /> function would use the two parameters to lookup the product and<br /> place the price in the corresponding row.<br /> <strong>example</strong>: onclick="addToCart("<em>product</em>",<em>price</em>)<br /> <br /> <strong>HINT</strong>: Keeping track of the rows is best done with a global variable. <br /> <strong>Note</strong>: Duplicate rows are allowed. <br /> <strong>Example</strong>: productName[0] and productName[2] could both contain<br /> Stapler. <br /> </li> <li>Build a function to display the arrays in the Shopping Cart area. This will run when the Display Cart button is clicked. It will also provide a total of the product prices. The total should be formatted as currency.<br /> <strong>Hint</strong>: Use <p> and .innerHTML to build an area to display and clear</li> <li>Build a function that will remove a product from the arrays. It will ask the user for the product name. The name should not be case sensitive. Remove the product and the corresponding price.</li> <li>Build a function that will remove all the products and corresponding prices from the arrays. This will run when the Clear Cart button is clicked.</li> </ol> </div> <div id="displayCart"> <h4 align="center">Shopping Cart</h4> <h4 align="center">List of Products</h4> <p align="center"><input name="" type="button" value="Clear Cart" /></p> <p>Today is: Month/dd/yyyy</p> </div> <div id="footer">Place today's date he (Day, Month date, year) ex: Monday January 1, 2012</div> </div> </body> </html> Its a ads rotation code: Don know why it doesnt work... Code: <body> <div align="center"> <script> var brw=navigator.appName; var id; if(brw == "Netscape") id=1; if(brw =="Microsoft Internet Explorer") id=2; if(brw == "Opera") id=3; var delay=10000; var k=0; var fcontent=new Array(); var b=new Array(); function go(k) { b[0]='' b[1]='<iframe src="http://........." width="460" height="60" scrolling="no" name="cpm" frameborder="0"></iframe>' b[2]='<iframe width="468" height="60" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://............"></iframe>' b[3]='<iframe width="468" height="120" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://............"></iframe>' if(id != 3) b[4]='<iframe width="1" height="1" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://......."></iframe>' else b[4]='' b[5]='..' ..... ..... b[36]='.... ' return; } begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations fcontent[0]=b[0]+b[1]+b[2]+b[3]+b[4]+b[5]; fcontent[1]=b[6]+b[7]+b[8]+b[9]+b[10]; fcontent[2]=b[11]+b[12]+b[13]+b[14]+b[15]; fcontent[3]=b[16]+b[17]+b[18]+b[19]+b[20]; fcontent[4]=b[21]+b[22]+b[23]+b[24]+b[25]; fcontent[5]=b[26]+b[27]+b[28]+b[29]+b[30]; fcontent[6]=b[31]+b[32]+b[33]+b[34]+b[35]; fcontent[7]=b[0]+b[36]; closetag='</div>'; var ie4=document.all&&!document.getElementById; var DOM2=document.getElementById; var index=0; //function to change content function changecontent(){ if (index>=fcontent.length ) { index=0; ++k;delay=delay+5000; } go(k); if(delay>15000){return;} if (DOM2){ document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag } else if (ie4) { document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag; } ++index; setTimeout("changecontent()", delay); } if (ie4||DOM2) document.write('<div id="fscroller" style="width:700px;"></div>'); if (window.addEventListener) window.addEventListener("load", changecontent, false) else if (window.attachEvent) window.attachEvent("onload", changecontent) else if (document.getElementById) window.onload=changecontent </script> </div> </body> here go(k); function might do this mass (output-->NaN). plz b a help... Hi, I am trying to create an array to pass to JQuery, but after several hours of trying, am falling over. I am trying to use Ajax to populate the javascript FullCalendar. I am trying to pass an arry to the following property: This works: $('#calendar').fullCalendar({ events: [{"id":1112,"title":"Event1","start":"2009-10-10"},{"id":222,"title":"Event2","start":"2009-10-20","end":"2009-10-22"}] }; something like: $('#calendar').fullCalendar({ events: MyJSArray() }; I will be using AJAX to populate MyJSArray(). I have tried the likes of: MyJSArray = new array("id"=>112,"title"=>"Event1", etc); But no joy I don't know how to get a javascript array into that format. I have my database values, but I need to put them into a format that the "Event" will accept. I have used PHP and arrays fine, but coming to grips with JS arrays,etc are a bit finiky at the moment. I am a little stuck, any help or points in the right direction will be much appreciated. Thanks Blueevo. Basically I am trying to retrieve my image path data from mysql to my variable created in my javascript. This is the code I m using. <?php $result = mysql_query("SELECT * FROM Shop"); while($row = mysql_fetch_array($result)) { $shopName[] = $row['ShopName']; $shopLogo[] = $row['ShopLogo']; $shopDescription[] = $row['ShopDescription']; $totalShops = count($shopName); } for($i=0; $i<totalShops; $i++){ echo "<script type='text/javascript'>"; echo "var logos = new Array();" echo "</SCRIPT>"; } ?> However, I cant solve the for loop part. I wanted to pass each and every data retrieved from mysql query into the array created in javascript part inside the for loop. Can anyone teach me how to do that? Thanks. Hi All, I'd be truly grateful if anyone can help me (a not so good JavaScripter). I'm trying to adapt some code. I have 3 chained select boxes which when the third is selected, I'd like to display specific info from the array within the HTML via the 'info' div. It works, but displays the whole array entry, and I'd just like to pick certain info from that entry. You can see my efforts within the 'categories["Nonfiction"]' entry - I've added the extra array elements to add another dimension to the array, but I think I've got into a muddle - can anyone help? So... when a user selects BOOKS > NONFICTION > COOKBOOKS I'd like just the 'Extra info 01' & 'Extra info 02' text to appear within the 'info' div. 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> <title>Interdependent Select Menus</title> <script type="text/javascript"> var categories = []; categories["startList"] = ["Books", "Clothes"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science Fiction","Romance", "Thrillers", "Crime"]; categories["Nonfiction"] = [["How-To", "Extra info 01", "Extra info 02"], ["Cookbooks", "Extra info 01", "Extra info 02"], ["Travel", "Extra info 01", "Extra info 02"] ]; categories["Clothes"] = ["Men","Women","Children"]; categories["Men"] = ["Shirts","Ties","Belts","Hats"]; categories["Women"] = ["Blouses","Skirts","Scarves", "Hats"]; categories["Children"] = ["Shorts", "Socks", "Coats", "Nightwear"]; var nLists = 3; // number of select lists in the set function fillSelect(currCat,currList){ var step = Number(currList.name.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms['tripleplay']['List'+i].length = 1; document.forms['tripleplay']['List'+i].selectedIndex = 0; } var nCat = categories[currCat]; for (each in nCat) { var nOption = document.createElement('option'); var nData = document.createTextNode(nCat[each]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(L3, L2, L1) { document.getElementById("info").innerHTML = L1 + "\n" + L2 + "\n" + L3; } function init() { fillSelect('startList',document.forms['tripleplay']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> </head> <body> <form name="tripleplay" action=""> <select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Make a selection</option> </select> <br /> <select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Make a selection</option> </select> <br /> <select name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected >Make a selection</option> </select> <div id="info">This is the default text</div> </form> </body> </html> |