JavaScript - Javascript Code Not Working...need Help
Can't get this to work...could someone read thru this and see if anything is missing? Thanks
Code: <html> <head> Supporting files: lhouse.css, list.js, logo.jpg <title>The Lighthouse</title> <link href="lhouse.css" rel="stylesheet" type="text/css" /> <script src="list.js" type="text/javascript"></script> <script type="text/javascript"> function amountTotal() { total(0); for (var i=0; i<=amount.length; i++) { total+=amount[i]; } return total; } </script> </head> <body> <div id=title> <img src=logo.jpg alt=The Lighthouse /> The Lighthouse<br /> 543 Oak Street<br /> Delphi, KY 89011<br/> (542) 555-7511 </div> <div id=data_list> <script type="text/javascript"> document.write("<table border=1' rules=rows cellspacing=0'>"); document.write("<tr><th>Date</th><th>Amount</th><th>First Name</th><th>Last Name</th><th>Address</th></tr>"); for (i=0; i< amount.length; i++) { if (i%2==0) document.write("<tr>"); else document.write("<tr class='yellowrow'>"); document.write("<td>"+date[i]+"</td>"); document.write("<td class=amt>"+amount[i]+"</td>"); document.write("<td>"+firstName[i]+"</td>"); document.write("<td>"+lastName[i]+"</td>"); document.write("<td>"); document.write("<td>"+street[i]+"<br/>"); document.write("city[i],+" +state[i]+ "+zip[i]"); document.write("</td>"); document.write("</tr>"); } document.write("</table>"); </script> </div> <div id=totals> <script type="text/javascript"> document.write("<table border=1' cellspacing=1'>"); document.write("<tr><th id=sumTitle colspan=2'>Summary</th></tr>"); document.write("<tr><th>Contributors</th>"); document.write("<td>+amount.length+</td></tr>"); document.write("<tr><th>Amount</th>"); document.write("<td>$+amountTotal()+</td></tr>"); document.write("</table>");</script> </div> </body> </html> </html> Similar TutorialsI havent even declared x,y and z as variables! Code: x=10; y=20; z = x+y; document.getElementById('good').innerHTML=z; I am getting so confused... since the time i started learning JS i thought declaring variables (var x,y,z was real important! This is suppose to execute "avalon" and it should move down the page once and "Books" should move with it, hidden behind it. I have read the code over and over and over and do not see any mistakes. HELP! Code: <title>Avalon Books</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="scripts.js" type="text/javascript"></script> <script type="text/javascript"> function placeObjects() { placeIt("avalon",175,10); placeIt("books", 175,10); placeIt("ab",230,40); placeIt("fiction",5,5); placeIt("nfiction",475,5); hideIt("ab"); hideIt("fiction"); hideIt("nfiction"); moveAvalon(); } function moveAvalon() { var y=yCoord("avalon"); if (y <= 260) { shiftIt("avalon",0,10); shiftIt("books",0,10); setTimeout("moveAvalon()",30); } else { moveBooks(); } } function moveBooks() { var x=xCoord("books"); if (x <= 320) { shiftIt("books",10,0); setTimeout("moveBooks()",50); } else { //display the hidden images; } } </script> </head> <body onload="placeObjects()"> <div id="avalon"> AVALON </div> <div id="books"> BOOKS </div> <div id="ab"> <a href="#"> <img src="ab.jpg" alt="Click to enter store" /> </a> </div> <div id="fiction"> <img src="fiction.jpg" alt="" /><br /> <b>AB Sales Rank: #1<br /> Fiction</b><br /> <i>Before the Fall</i><br />Jeffrey Unwin </div> <div id="nfiction"> <img src="nfiction.jpg" alt="" /><br /> <b>AB Sales Rank: #1<br /> Nonfiction</b><br /> <i>Vietnam Memoirs</i><br />Gen. John Hartford </div> </body> </html> So I have a file that factors quadratics. It works just fine when I open the file from my desktop, but when I upload it and try to use it, the javascript stops working. Any ideas? This is the file: http://wdroom.com/factor.html You can try it out there, or you can download it. I can't get it to work at all for some reason... Thanks! I have a webpage where I have declared a variable as Code: <input type="hidden" id="Edits_OK" /> I set the value of this variable within a Javascript function to either "T" or "F". In my code-behind, I have a btnSubmit_Click() event that calls this Javascript function. In this code-behind event, I also check the value of the "Edits_OK" variable, however, the value is always "". The Javascript function will always put a value in this variable whether it's "T" or "F". I also declare the "Edits_OK" variable within the code-behind as this: Code: Private Edits_OK As New HiddenField Here is the Javascript Function. Code: function CheckEdits() { var msg; document.getElementById("Edits_OK").value = 'T'; if (document.getElementById("txtName").value == '') { msg = msg + '\nName'; document.getElementById("Edits_OK").value = 'F'; } if (document.getElementById("txtOrganization").value == '') { msg = msg + '\nOrganization'; document.getElementById("Edits_OK").value = 'F'; } if (document.getElementById("txtSubject").value == '') { msg = msg + '\nSubject'; document.getElementById("Edits_OK").value = 'F'; } if (document.getElementById("txtNote").value == '') { msg = msg + '\nNote'; document.getElementById("Edits_OK").value = 'F'; } if (document.getElementById("Edits_OK").value == "F") { var msg2; msg2 = "Please provide the following information:\n"; error_occurred = true; alert(msg2 + msg); } } Here is the code-behind Procedu Code: Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click Try If Edits_OK.Value = "T" Then FormatEmail() End If Catch ex As Exception lblErrMsg.Text = "btnSubmit_Click() Event - " & ex.Message End Try End Sub Not sure why the value is always "". Please help! Thanks! Hey guys-I realize that this is a javascript/php hybrid, but I am having a strange problem here. Basically, this script uploads an image (from another page), then allows you to crop it and save it. I want to have it redirect back to the original page in the form of a php header (see if $_GET['action']==done). However, it doesn't seem to want to send the header! This is strange because my first header, right above the second, that redirects to an error page, works just as planned. Here is the code. The headers I've added are very close to the top. Code: <?php /* * Copyright (c) 2008 http://www.webmotionuk.com * "PHP & Jquery image upload & crop" * Date: 2008-05-15 * Ver 1.0 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * http://www.opensource.org/licenses/bsd-license.php */ if ($_GET['action']=="done") { if ($_POST['x1']=="" || $_POST['y1']=="" || $_POST['x2']=="" || $_POST['y2']=="" || $_POST['w']=="" || $_POST['h']=="") { header("Location: profile.php?action=cropError"); } } if ($_GET['action']=="done") { header("Location: profile.php"); } session_start(); $userid = $_SESSION['userid']; //Constants //You can alter these options $upload_dir = "uploadPic"; // The directory for the images to be saved in $upload_path = $upload_dir."/"; // The path to where the image will be saved $large_image_name = $userid."full.jpg"; // New name of the large image $thumb_image_name = $userid."thumb.jpg"; // New name of the thumbnail image $max_file = "100000"; // 100KB $max_width = "500"; // Max width allowed for the large image $thumb_width = "175"; // Width of thumbnail image $thumb_height = "234"; // Height of thumbnail image //Image functions //You do not need to alter these functions function resizeImage($image,$width,$height,$scale) { $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); $source = imagecreatefromjpeg($image); imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height); imagejpeg($newImage,$image,90); chmod($image, 0777); return $image; } //You do not need to alter these functions function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){ $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); $source = imagecreatefromjpeg($image); imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height); imagejpeg($newImage,$thumb_image_name,90); chmod($thumb_image_name, 0777); return $thumb_image_name; } //You do not need to alter these functions function getHeight($image) { $sizes = getimagesize($image); $height = $sizes[1]; return $height; } //You do not need to alter these functions function getWidth($image) { $sizes = getimagesize($image); $width = $sizes[0]; return $width; } //Image Locations $large_image_location = $upload_path.$time.$large_image_name; $thumb_image_location = $upload_path.$time.$thumb_image_name; //Create the upload directory with the right permissions if it doesn't exist if(!is_dir($upload_dir)){ mkdir($upload_dir, 0777); chmod($upload_dir, 0777); } //Check to see if any images with the same names already exist if (file_exists($large_image_location)){ if(file_exists($thumb_image_location)){ $thumb_photo_exists = "<img src=\"".$upload_path.$thumb_image_name."\" alt=\"Thumbnail Image\"/>"; }else{ $thumb_photo_exists = ""; } $large_photo_exists = "<img src=\"".$upload_path.$large_image_name."\" alt=\"Large Image\"/>"; } else { $large_photo_exists = ""; $thumb_photo_exists = ""; } if (isset($_POST["upload"])) { //Get the file information $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $filename = basename($_FILES['image']['name']); $file_ext = substr($filename, strrpos($filename, '.') + 1); //Only process if the file is a JPG and below the allowed limit if((!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0)) { if (($file_ext!="jpg") && ($userfile_size > $max_file)) { $error= "ONLY jpeg images under 100KB are accepted for upload"; } }else{ $error= "Select a jpeg image for upload"; } //Everything is ok, so we can upload the image. if (strlen($error)==0){ if (isset($_FILES['image']['name'])){ move_uploaded_file($userfile_tmp, $large_image_location); chmod($large_image_location, 0777); $width = getWidth($large_image_location); $height = getHeight($large_image_location); //Scale the image if it is greater than the width set above if ($width > $max_width){ $scale = $max_width/$width; $uploaded = resizeImage($large_image_location,$width,$height,$scale); }else{ $scale = 1; $uploaded = resizeImage($large_image_location,$width,$height,$scale); } } //Refresh the page to show the new uploaded image header("location:".$_SERVER["PHP_SELF"]); exit(); } } if (isset($_POST["upload_thumbnail"]) && strlen($large_photo_exists)>0) { //Get the new coordinates to crop the image. $x1 = $_POST["x1"]; $y1 = $_POST["y1"]; $x2 = $_POST["x2"]; $y2 = $_POST["y2"]; $w = $_POST["w"]; $h = $_POST["h"]; //Scale the image to the thumb_width set above $scale = $thumb_width/$w; $cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale); //Reload the page again to view the thumbnail header("location:".$_SERVER["PHP_SELF"]); exit(); } if ($_GET['a']=="delete"){ if (file_exists($large_image_location)) { unlink($large_image_location); } if (file_exists($thumb_image_location)) { unlink($thumb_image_location); } header("location:".$_SERVER["PHP_SELF"]); exit(); } if($_GET['action']=="done"){ include('functions.php'); dbconnect(); $query = "UPDATE user SET picture='$thumb_image_name' WHERE userid='$userid'"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query"); $_SESSION['picture'] = $thumb_image_name; header( "refresh:0;url=profile.php" ); } include('top.php'); ?> <!-- * Copyright (c) 2008 http://www.webmotionuk.com / http://www.webmotionuk.co.uk * Date: 2008-05-15 * Ver 1.0 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * http://www.opensource.org/licenses/bsd-license.php --> <?php //Only display the javacript if an image has been uploaded if(strlen($large_photo_exists)>0){ $current_large_image_width = getWidth($large_image_location); $current_large_image_height = getHeight($large_image_location);?> <script type="text/javascript"> function preview(img, selection) { var scaleX = <?php echo $thumb_width;?> / selection.width; var scaleY = <?php echo $thumb_height;?> / selection.height; $('#thumbnail + div > img').css({ width: Math.round(scaleX * <?php echo $current_large_image_width;?>) + 'px', height: Math.round(scaleY * <?php echo $current_large_image_height;?>) + 'px', marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' }); $('#x1').val(selection.x1); $('#y1').val(selection.y1); $('#x2').val(selection.x2); $('#y2').val(selection.y2); $('#w').val(selection.width); $('#h').val(selection.height); } $(document).ready(function () { $('#save_thumb').click(function() { var x1 = $('#x1').val(); var y1 = $('#y1').val(); var x2 = $('#x2').val(); var y2 = $('#y2').val(); var w = $('#w').val(); var h = $('#h').val(); if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){ alert("You must make a selection first"); return false; }else{ return true; } }); }); $(window).load(function () { $('#thumbnail').imgAreaSelect({ aspectRatio: '175:234', onSelectChange: preview }); }); </script> <?php } ?> <?php //Display error message if there are any if(strlen($error)>0){ echo "<ul><li><strong>Error!</strong></li><li>".$error."</li></ul>"; } if(strlen($large_photo_exists)>0){?> <img src="<?php echo $upload_path.$large_image_name;?>" style="float: left; margin-right: 10px;" id="thumbnail" alt="Create Thumbnail" /> <div class="cropInstructions"> <?php if ($_GET['action']=="done") { echo "<h3>Picture Updated!</h3>"; } ?> <h3>Crop Profile Picture</h3><p>To crop the photo, simply click your mouse on the picture to the left and drag it to the desired size.</p> <br style="clear:both;"/> <form name="thumbnail" action="cropImage.php?action=done" method="post"> <input type="hidden" name="x1" value="" id="x1" /> <input type="hidden" name="y1" value="" id="y1" /> <input type="hidden" name="x2" value="" id="x2" /> <input type="hidden" name="y2" value="" id="y2" /> <input type="hidden" name="w" value="" id="w" /> <input type="hidden" name="h" value="" id="h" /> <input type="hidden" name="done" value="yes" id="done" /> <input type="submit" name="upload_thumbnail" value="Save Thumbnail" class="cropButton" /> </form><br> <a href="profile.php">Back To Edit Profile</a> </div> <?php } include('bottom.php'); ?> <!-- Copyright (c) 2008 http://www.webmotionuk.com --> </body> </html> hi there, i have a problem which is there is some javascript codes keeping the #usemap tag from working here is my webpage Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta content='text/html; charset=windows-1256' http-equiv='Content-Type' /> <title>Assiut map</title> <script src="shiftzoom.js" language="javascript" type="text/javascript"></script> <script type="text/javascript"> <!-- if(document.images&&document.createElement&&document.getElementById){ document.writeln('<style type="text/css">'); document.writeln('img.shiftzoom { visibility: hidden; }'); document.writeln('<\/style>'); } shiftzoom.defaultCurpath = 'images/cursors/'; //--> </script> </head> <body> <div id="content"> <div style="float: left; width:700px; height:300px; border:1px solid gray; margin-right: 1em; margin-bottom: 0.25em;"> <div style="width:700px; height:300px; background: url(images/indicator.gif) 50% 50% no-repeat;"> <img id="map" usemap="#map" class="shiftzoom" onLoad="shiftzoom.add(this,{showcoords:false,zoom:100});" src="assiut.jpg" width="700" height="300" alt="large image" border="0" /> </div></div></div> <map name="map" id="map"> <area shape="circle" coords="250,160,15" href="#nowhere" title="Ahmed house<br>name:ahmed<BR>Class:1-1" alt="" /> <area shape="circle" coords="110,164,15" href="#nowhere" title="Mohamed house<br>name:Mohamed<BR>Class:2-1" alt="" /> <area shape="circle" coords="190,362,15" href="#nowhere" title="Mostafa house<br>name:Mostafa<BR>Class:3-1" alt="" /> </map> </body> </html> the .js file in attachments which have somthing that keeps the #usemap from working, would be so thankful if anyone could help thanks I hope I have this post in the right place! Any help would be very much appreciated... I have a feature on my website that allows users to choose the website background (using alternate css sheets) and then uses an externally linked javascript file to store the background choice as a cookie so it is consistent throughout the website. This works perfectly locally (i.e. when previewing my website on my computer) but now it is uploaded to my host it doesn't appear to be working. (with the same browser) My javascript is he http://www. b r p - e n v .com/javascript/backgroundchange.js (with no spaces) The website that the javascript file is linked to is http://www. b r p - e n v .com (with no spaces) In the head I have: <script type="text/javascript" src="../javascript/backgroundchange.js"></script> ...then I have: <body onload="set_style_from_cookie()"> ...and for users to choose which background: <form> <input type="image" src="../images/white-background-thumb.jpg" onclick="switch_style('bg1');return false;" name="theme" value="White" id="bg1"> etc... </form> My problem is: The background reverts back to the default when moving to a different page. This would indicate that the background choice is not being saved in cookies. But this works locally! I have tried putting the javascript directly onto each page but I still had the same problem. I hope someone can help, I will be so grateful if I can get this to work. Many thanks indeed! Hey everyone here is my code for looking up a city, and state by zip code. I am getting no errors and i believe it should work, but the code does not seem to want to function. Any ideas? Here is my 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>City and State Lookup</title> <style type="text/css"> h1 { font-family:Arial; color:navy; } p, td { font-family:arial; font-size:11px; } </style> <script type="text/javascript"> /* <![CDATA[ */ var httpRequest = false; function getRequestObject() { try { httpRequest = new XMLHttpRequest(); } catch (requestError) { try { httpRequest = new ActiveXObject ("Msxm12.XMLHTTP"); } catch (requestError) { try { httpRequest = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (requestError) { window.alert("Your browser does not support AJAX!"); return false; } } } return httpRequest; } function updateCityState() { if (!httpRequest) httpRequest = getRequestObject(); httpRequest.abort(); httpRequest.open("get","zip.xml"); httpRequest.send(null); httpRequest.onreadystatechange=getZipInfo; } function getZipInfo() { if (httpRequest.readyState==4 && httpRequest.status == 200) { var zips = httpRequest.responseXML; var locations = zips.getElementsByTagName("Row"); var notFound = true; for (var i=0; i<locations.length; ++i) { if (document.forms[0].zip.value == zips.getElementsByTagName( "ZIP_Code")[i].childNodes[o].nodeValue) { document.forms[0].city.value = zips.getElementsByTagname( "City") [i].childNodes[0].nodeValue; document.forms[0].state.value = zips.getElementByTagName( "State_Abbreviation")[i].childNodes[0].nodeValue; notFound = flase; break; } } if (notFound) { window.alert("Invalid ZIP code!"); document.forms[0].city.value = ""; document.forms[0].state.value = ""; } } } /* ]]> */ </script> </head> <body> <h1>City and State Lookup </h1> <form action=""> <p>Zip code <input type="text" size="5" name="zip" id="zip" onblur="updateCityState()" /></p> <p>City <input type="text" name="city" /> State <input type="text" size="2" name="state" /></p> </form> </body> </html> hereis the html file and javascripton click of this button a html ***************************** <table class=matcolor id=topnav cellspacing=0 cellpadding=0 width=550 border=0 bgcolor="#FFCCCC"> <tbody> <tr align=middle> <td id=menu1 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Desk Top Publishing </font></div> </td> <td width=1 bgcolor=#ff9900 class="mat"></td> <td id=menu2 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Transcription</font></div> </td> <td width=1 bgcolor=#ff9900 class="mat"></td> <td id=menu3 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Accounts Processing </font></div> </td> </tr> </tbody> </table> ***************************************** <script language=JavaScript> ix = document.getElementById('tblmenu1').getBoundingClientRect(); new ypSlideOutMenu("menu1", "right",ix.left + ix.right ,ix.bottom + 10); </script> **any thing i have to alter to work in firefox please help Hey all, I have a javascript object which I have created and it works fine until I remove the second message box from the program steps. The alert box was only ever meant to be there for error debugging to steop me through the code. Any ideas? Code: function hyper() { this.test = ""; this.load = function(lib, ver) { alert("Starting API Library Load"); var oHead = document.getElementsByTagName('HEAD').item(0); var oScript= document.createElement("script"); oScript.type = "text/javascript"; oScript.src=lib + "/" + ver + "/api.js"; oHead.appendChild( oScript); alert("Finished Loading Library"); switch(lib) { case "test": this.test = new test(); break; case "ads": this.ads = new HAds(); break; case "chat": this.chat = new HChat(); break; case "survey": this.survey = new HSurvey(); break; default: alert("No Library"); }; } } Hey guys, I am not sure why this JavaScript is not working. Can you check it out please? Thanks. --Start-- <html> <head> <title>Guess it up! </title> </head> <body> <center> <b><font size="5" ><u><b>Guess it up!<br></b></u> <br > <font size="3" > This is out of five! <br > Type in your guess: <p> </p> </font> <input name="HisGuess" type="text" size=1 value=1> <p> <input name="StartButton" type="button" value="Guess" onclick="StartGame()"> </p> <p> <script> var TheRightNumber = Math.round(Math.random * 5); function StartGame() { if (TheRightGuess == HisGuess){ alert("You got it! Nice!") else{ alert("Guess again!") } } </script> --END-- Can anyone tell my why this is not working? All answers are appreciated. I wrote a script that should loop through the list of countries, and if the entry's width exceeds 70px, it should cut the extra letters and insert "..." at the end of the entry; My codes produces unexpected results. The script only modifies the entry"United States", by replacing it with "Cook Isla...". I suspect I don't use the while loop properly. Plus the script does not work at all in IE. Could someone have a look and give me a hint what went wrong. Thank you very much!!! Code: <html> <head> <title> Ellipse Practice </title> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <style type="text/css"> ul { width: 200px; margin-left: 100px; } span { white-space: nowrap; } </style> <script type="text/javascript"> function trancateAll() { var list=document.getElementsByTagName("li"); count=0; while (count<list.length) { var text=String(list[count].innerHTML); list[count].innerHTML='<span id="mySpan">'+text+'</span>'; mySpan=document.getElementById("mySpan"); mySpan.innerHTML=''; var charac=1; while( (mySpan.offsetWidth<70) && (charac<text.length)) { mySpan.innerHTML=text.substr(0,charac)+"..."; charac++; } count++; } } </script> </head> <body > <ul> <li> United States</li> <li> Australia</li> <li> New Zealand</li> <li> Democratic Republic of Congo</li> <li> Russian Federation</li> <li> Cook Islands</li> </ul> <input type="button" value="Truncate" onclick="trancateAll()"/> </body> </html> I changed the code and it didn't work, so I tried to put it back to what it was. Now, the whole thing isn't working. I am a lost little child. Can someone help me please. http://www.boothemusic.com/ Here is the code: Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head xmlns=""> <title>Boothe Brothers Music</title> <script type="text/javascript"> function loadContent(page) { switch(page) { case "home": document.getElementById("middle").src = "http://boothemusic.com/middle.html"; break; case "store": document.getElementById("middle").src = "http://boothemusic.com/catalog"; break; case "Electric Guitars": document.getElementById("middle").src = "http://boothemusic.com/catalog/index.php?main_page=index&cPath=1&zenid=9feb6660698a06a51571cc4cef1c3e60"; I left out most of the code because I only edited the line "case "store".....". Code: function addEvent(elem,type,func) { var obj = document.getElementById(elem); if(window.addEventListener) { obj.addEventListener(type,func,false); } if(window.attachEvent) { obj.attachEvent('on'+type,func); } } function $e(obj) { if(obj) obj = document.getElementById(obj); if(!obj) return; return obj; } function homeFunc() { $e('home-wrapper').innerHTML = "<div id=\"choose-container\"><span class=\"choose-buttons\" onclick=\"loginFunc()\">Login Exisiting Account</span><span class=\"choose-buttons\" id=\"createAcct\">Create An New Account</span><span class=\"choose-buttons-highscores\" id=\"createAcct\">Highscores Table</span>"; } function loginFunc() { $e('home-wrapper').innerHTML = "<div id=\"login-container\"><div id=\"error-field\"></div><form method=\"post\" onsubmit=\"return validate_login()\" action=\"./index.php\"><label for=\"username\">Username</label><input name=\"username\" id=\"username\" class=\"input\" type=\"text\" /> <label for=\"password\">Password</label><input name=\"password\" id=\"password\" class=\"input\" type=\"password\" /><input name=\"login\" type=\"submit\" value=\"Login\" class=\"loginButtonClass\" /><div id=\"loginQuickLinks\"><span class=\"loginQuickLinks\" onclick=\"homeFunc()\">Register</span> - <span class=\"loginQuickLinks\">Forgot password?</span></form></div></div>"; } function createAcct() { alert("Create An Account"); } function validate_usr() { var usr = $e('username'); var pwd = $e('password'); if(usr.value.length <= 0 && pwd.value.length <= 0) { loginErrorMsg('Please supply a username and password.'); return false; } if(usr.value.length >= 1 && pwd.value.length <= 0) { loginErrorMsg('Please supply a password.'); return false; } if(pwd.value.length >= 5 && usr.value.length <= 0) { loginErrorMsg('Please supply a username.'); return false; } if(pwd.value.length < 5) { loginErrorMsg('Invalid username or password.'); return false; } if(usr.value.length >= 1 && pwd.value.length >= 5) { $e('error-field').style.cssText='display:block;'; $e('error-field').innerHTML = "<img src=\"/images/ajax-loader.gif\" /> <span style=\"color:#ffffff\">Loading...</span>"; var req; var params = 'user='+encodeURIComponent(usr.value.toLowerCase())+'&pass='+encodeURIComponent(pwd.value.toLowerCase()); if(window.XMLHttpRequest) { req = new XMLHttpRequest(); } if(window.ActiveXObject) { req = new ActiveXObject("Msxml2.XMLHTTP" || "Microsoft.XMLHTTP"); } req.open('POST','server/userChck.php',true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send(params); req.onreadystatechange = req; if(req.readyState == 4 && req.status == 200) { if(req.responseText == 0) { window.scrollTo(0,1); setTimeout(function(){loginErrorMsg('Invalid username or password');},1000); return false; } } } return true; } function loginErrorMsg(msg) { window.scrollTo(0,1); $e('error-field').innerHTML = msg; $e('error-field').style.cssText='display:block'; } function validate_login() { var isTurn = (!validate_usr()) ? false : true; return isTurn; } window.onload = function() { setTimeout(function(){window.scrollTo(0,1);},100); addEvent('loginButton','click',loginFunc); addEvent('createAcct','click',homeFunc); } This code works fine when I set this line to false Code: req.open('POST','server/userChck.php',false); but as soon as I set this to true. I doesn't work.... What am I doing wrong here? Hi, Please help code not working.i want the alert message to pop up when a cmbprop is selected. <script type="text/javascript"> function PropertyOwn(property) { prop=document.frmone.cmbprop.value switch(property) { case"0": // no error occured break case"1": alert("I am a rich men") break case"2": alert("i am a poor men") break case"3": alert("Thank God for this opportunity") break default: alert("Just try again") } } </script> <form name="frmone"> <select name="cmbprop" onchange="propertyOwn(this.value)"> <option value=0>--choose from one--</option> <option value=1>I have BMW</option> <option value=2>I rent a sigle room</option> <option value=3>Seing possibilities</option> </select> </form> Thanks. Clement Osei index.html Code: <html> <head> <title>:: wtmp</title> </head> <body> <p>Welcome to my page</p> <script type="text/javascript" src="file.js"></script> </body> </html> file.js Code: function one(p1, p2) { var j_text=p1+" "+p2; return j_text; } function two() { var rslt=one("Hi", "there!"); } document.write(rslt); var mainscrpt=one("Hello", "world!"); window.alert(mainscrpt); This code originally worked, but now it doesn't. It's suppose to count the number of characters you type. The form processes fine, but it's not counting, it always says 1,000 in the box. Any ideas? Thanks Code: <script type = "text/javascript"> var maxLen = 1000; // max number of characters allowed // global variable var max = "You may enter up to " + maxLen + " characters"; // global variable function OnPaste () { //return false; // cancels (blocks) the onpaste event. Uncomment this line to block pasting setTimeout(checkMaxInput,100); // delay is necessary } function initCount() { document.getElementById("limit").innerHTML = max; document.getElementById("remLen").value = maxLen; } function checkMaxInput() { var form = document.myform; // or document.forms[0] or document.getElementById("myform"); if (form.txtarea.value.length > maxLen) { // if too long.... trim it! form.txtarea.value = form.txtarea.value.substring(0, maxLen); document.getElementById("message").innerHTML = "Too many characters were entered!! The excess over " + maxLen + " have been removed."; } else { document.getElementById("message").innerHTML = ""; } form.remLen.value = maxLen - form.txtarea.value.length; } </script> <body onload = "initCount()"> <form name = "myform" id = "myform"> <span id = "limit" style="font-size: 10pt;color: #FF0000;font-family: arial, helvetica, sans-serif;"></span> <br> <textarea name="txtarea" wrap=physical cols=48 rows=10 onkeyup="checkMaxInput()" onblur="checkMaxInput()" onpaste="OnPaste ()" > </textarea> <br> <input readonly type=text name=remLen id = "remLen" size=3 value = ""> characters left</font> </form> <span id = "message" style="color:red";></span> This code is not working correctly when you type get_data it should only work if you already have typed load_hacker. But get_data works withought load_hacker.
Code: <script type="text/javascript"> function command(){ if(command.value = "load_hacker" && level.value == 1){ document.getElementById("command").value = ""; document.getElementById("number").value = ""; plus(); } else { document.getElementById("command").value = "..."; document.getElementById("number").value = "..."; } if(command.value = "get_data" && level.value == 2){ document.getElementById("command").value = ""; document.getElementById("number").value = ""; plus(); } else { document.getElementById("number").value = "..."; document.getElementById("command").value = "..."; } } </script> <script type="text/javascript"> function plus(){ document.getElementById("level").value ++; } </script> ><input type="text" value="" id="command" size="" style="background-color:transparent;border:0px solid white;" /> #<input type="text" value="" id="number" size="10" style="background-color:transparent;border:0px solid white;" /> <input type="button" value="Enter" onclick="command()" /> <input type="hidden" value= 1 id="level" /> Any idea why this doesn't work? I'm trying to hide the li with ID of facebook1 if the innerHTML is one of two things. But if both return false and there is more code in there (e.g. a full url), I want to show the li with ID of facebook1 and also add the text 'Facebook Profile' to the span with ID of fbook-add. Code: <ul> <li id="facebook1"><a href="http://facebook.com"><span id="fbook-add"></span></a></li> </ul> <script type="text/javascript"> if(document.getElementById('facebook1').innerHTML.toLowerCase()=='<a href="http://"><span id="fbook-add"></span></a>') { document.getElementById('facebook1').style.display='none'; } else if(document.getElementById('facebook1').innerHTML.toLowerCase()=='<a href=""><span id="fbook-add"></span></a>') { document.getElementById('facebook1').style.display='none'; } else { document.getElementById('fbook-add').innerHTML=='Facebook Profile'; } </script> |