JavaScript - How To Test If Js Is Turns Off ?
I have Javascript on my site and will not work at all if JS is disabled.
How do I notify my users that the pull down menus use javascript and will not work unless they turn it on? Similar TutorialsI've gone far enough with my website and thanks to you guys i completed a lot of issues i had. I just included a browser detect snippet which is supposed to show the pages correctly on IE, Firefox, Safari, Opera and Chrome. I understand that watching a greek site won't make much sense for you, but i'm hoping you will at least understand how the thing goes. The first yellow box on your left is the menu. Clicking there will take you to the menu's categories. You will find a few categories in english there, at least Now, in each category, clicking the button below the product should put it in the cart, part of it appears on every page in a floating layer to the top-right. There is also a link in there to "checkout" (ΟΛΟΚΛΗΡΩΣΗ ΠΑΡΑΓΓΕΛΙΑΣ). This is where the problem comes: In every browser except Chrome, the list of items of the cart will appear. I don't know why but in Chrome, not only i see nothing in there, but it also deletes everything in the cart! If any of you, specially the ones who have many browsers installed, could spend a little time testing my site, i would really appreciate it. Old Pedant and Phillip should be more aware since you guys have already helped me out and you kinda know the functionality of the site. The address is: lukulos.gr (works directly now, no need to type specific files) hello guys, I'm new here .. I am developing a fw js, now I have to test the selector $.. operation is similar to jquery $('#Id') $('table td .class) If there are several factors you should: $('table td .class).each(function () { this .. }); or $('table td .class).item(number) ... http://debbe.altervista.org/d&d.html can be used to test the methods set / get the attributes or setCSS or getCSS for styles .. Thanks to all Hi All, I am looking to make a "enemy" dissapear when "character" hits it? I don't really know what I'm doing. All help is appreciated! PHP 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style> body { padding:0; margin:0; background:#000; } canvas { display:block; margin:30px auto 0; border:1px solid #ccc; background:#999; } </style> <script> var canvas, ctx, width = 320, height = 480, rightKey = false, leftKey = false, enemyTotal = 4, enemies = [], enemy_x = 50, enemy_y = 1, enemy_w = 32, enemy_h = 32, speed = 1, character_x = (width / 2) - 15, character_y = height - 65, character_w = 32, character_h = 32, level_1, level_1_bgX = 0, level_1_bgY = -1312; var enemy, character; for (var i = 0; i < enemyTotal; i++) { enemies.push([enemy_x, enemy_y, enemy_w, enemy_h, speed]); enemy_x += enemy_w + 30; } function drawEnemies() { for (var i = 0; i < enemies.length; i++) { ctx.drawImage(enemy, enemies[i][0], enemies[i][1]); } } function moveEnemies() { for (var i = 0; i < enemies.length; i++) { if (enemies[i][1] < height) { enemies[i][1] += enemies[i][4]; } else if (enemies[i][1] > height - 1) { enemies[i][1] = -45; } } } function clearCanvas() { ctx.clearRect(0,0,width,height); } function drawCharacter() { ctx.drawImage(character, character_x, character_y); if (rightKey) character_x += 5; else if (leftKey) character_x -= 5; if (character_x <= 0) character_x = 0; if ((character_x + character_w) >= width) character_x = width - character_w; } function drawlevel_1() { ctx.drawImage(level_1,level_1_bgX,level_1_bgY); if (level_1_bgY > 1792) { level_1_bgY = -1791; } level_1_bgY += 1.5; } function init() { canvas = document.getElementById('canvas'); ctx = canvas.getContext('2d'); enemy = new Image(); enemy.src = 'character_1.gif'; character = new Image(); character.src = 'character_1.gif'; level_1 = new Image(); level_1.src = 'level_1.jpg'; setInterval(gameLoop, 25); document.addEventListener('keydown', keyDown, false); document.addEventListener('keyup', keyUp, false); } function gameLoop() { clearCanvas(); drawlevel_1(); moveEnemies(); drawEnemies(); drawCharacter(); } function keyDown(e) { if (e.keyCode == 39) rightKey = true; else if (e.keyCode == 37) leftKey = true; } function keyUp(e) { if (e.keyCode == 39) rightKey = false; else if (e.keyCode == 37) leftKey = false; } window.onload = init; </script> </head> <body> <canvas id="canvas" width="320" height="480"></canvas> </body> </html> Thanks Code: <html> <head> <script> function testemail(){ var fld= document.getElementById("input1").value; var reg = /^[\w+]@[\w+].com$/i; if(reg.test(fld)) { alert("email is ok"); } else { alert("email is not correct"); } } </script> </head> <body> <p> <form name="form1" onsubmit="testemail()"> enter email : <input id="input1" type="text" /> <input id="input2" type="submit" value="Submit" /> </form> </p> </body> </html> I am trying to test an email ID with above RegExp. I enter a correct email or not, I am always getting message "email is not correct" So RegExp is not working. How can I find out whats wrong with this RegExp ? Is there any tool to figure that out ? I tried with FireBug, but it does not point to whats wrong with RegExp Thanks Can someone advise me how I could get this websocket to work. I'm working off a tutorial which gives this example. Code: var connection = new WebSocket('ws://html5rocks.websocket.org/echo', ['soap', 'xmpp']); // When the connection is open, send some data to the server connection.onopen = function () { connection.send('Ping'); // Send the message 'Ping' to the server }; // Log errors connection.onerror = function (error) { console.log('WebSocket Error ' + error); }; // Log messages from the server connection.onmessage = function (e) { console.log('Server: ' + e.data); }; This does work and I can write something similar can get the correct results as long as I am connecting to that address. I am not able to get the same results from my server and I cannot even get the sockets onopen function to run. Here is my JS Code- Code: socket = new WebSocket("ws://micahwilliamson.com:80/socket.php", ['soap', 'xmpp']); socket.onmessage = function(e) { alert(e.data); } socket.onopen = function() { alert("Success"); socket.send("test"); } socket.onerror = function(err) { alert(err); } Here is my php socket code. Code: <?php ini_set("display_errors", 1); $host = "localhost"; $port = 80; $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket"); $bind = socket_bind($socket, $host, $port) or ("Could not bind to socket"); $listen = socket_listen($socket, 3) or die("Could not listen to socket"); $spawn = socket_accept($socket) or die("Could not accept incoming connection"); $input = socket_read($spawn, 1024) or die("Could not read input"); $input = trim($input); $output = strrev($input); socket_write($spawn, $output, strlen($output)) or die("Could not write to socket"); socket_close($spawn); socket_close($socket); ?> It seems the socket cannot make a connection so it could be my php code or the file hosting server just wont allow it. I got a VPS- maybe that would work better? Code: //Script to Rotate Images and Transition Effects var slidespeed=2000 var slideimages=new Array("1.jpg","2.jpg","3.jpg") var whichimage=0 var imgobj, filtersupport, blenddelay var imageholder=new Array() for (i=0;i<slideimages.length;i++){ //preload images imageholder[i]=new Image() imageholder[i].src=slideimages[i] } function slideit(){ if (filtersupport) imgobj.filters[0].apply() imgobj.src=imageholder[whichimage].src if (filtersupport) imgobj.filters[0].play() whichimage=(whichimage<slideimages.length-1)? whichimage+1 : 0 setTimeout("slideit()", slidespeed+blenddelay) } //End Image Rotation/Transistion What object can I test for instead of "filtersupport" so that I can have an else {} for non-ie browsers? Hello, I am trying to complete a test site but adding some javascript. In short I am trying to make the main content div slide from behind the nav via some JS. http://www.squareflash.com/test/index.html First I am just trying to get the animate onClick to work. I found this practice site -- Using this I am trying to get some guidance on how to add a automatic stop function to the moveRight variable. http://www.tutorialspoint.com/cgi-bi...=javascript_45 The site is in html5, is there anything special I need to know for that? ty Hey all, I am doing an image/data rotating script. I get the data from a XML. I parse that data and build the divs and such. Data Set 1 --- background image in a div, with a button and some text overlayed on the div. ... ... Data Set 4 -- etc.. The thing is, I load the script and the div appears, BUT the text overlay appears first THEN the image pops up for the first Data Set. I can't have that. I need them both to appear at once. Is there a way to determine that a div background image is loaded? -- I have access to the prototype js library. thanks. Hello! I am trying to validate name, email and comment inputs! I did the following! Code: $("#CmtSub").click(function(event){ var email = $("#CmtEmail").val(); var filter = /'^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$'/; if( $("#CmtName").val() == "" ){ $("#CmtName").css({'background-position': '0 -45px'}, 0); return event.preventDefault(event); }else{ $("#CmtName").css({'background-position': '0 -90px'}, 0); } if(filter.test(email) && email != "") { $("#CmtName").css({'background-position': '0 -45px'}, 0); return event.preventDefault(event); }else{ $("#CmtName").css({'background-position': '0 -90px'}, 0); } //just to debug console.log("the value and the email ("+ email +")"); if( $("#CmtTxtArea").val() == "" ){ $("#CmtTxtArea").css({'border': 'red 1px solid'}, 0); return event.preventDefault(event); }else{ $("#CmtTxtArea").css({'border': 'white 1px solid'}, 0); } // then proceed ! }); this code here isn't working! any help please ?: Code: if(filter.test(email) && email != "") { //passme = false; $("#CmtName").css({'background-position': '0 -45px'}, 0); return event.preventDefault(event); }else{ //passme = true; $("#CmtName").css({'background-position': '0 -90px'}, 0); } help is greatly appreciated ! I am not a JAVA programmer. However I expected to find a similar template on the web. I couldn't. A list of checkbox options: 1. Water 2. Sand 3. Red paint Submit button which brings results IF Water and Sand selected, result = Mud IF Water and Red paint selected, result = Red water The closest thing I got to was http://www.javaworld.com/javaworld/j...orm_check.html How would code for such a program look like? Ideally I would want it to be really simple. Paste to notepad and save as html. I would like to create a quiz/test, and I would like it to be corrected by Javascript--where when the user clicks the submit button, it will show the user "You got number% correct." How can I do this?
When looping thru a group of elements and using getNamedItem('itemname').value there are some elements that are going to have a null value for that particular getNamedItem... the problem is that you cannot test this value to see if it's null because it generates an error instead, and the code does not continue: _allnames[_j].attributes.getNamedItem("onchange") is null You cannot even test it for null like this: if (_allnames[_j].attributes.getNamedItem("onchange").value != null) { do something } This will also generate an Error instead of testing to see if it is null. How do you test getNamedItem for null to avoid this error? EDIT: It appears that the problem is limited to Firefox. It works fine in IE7, but the error occurs in both FF v3.5.4 and in v3.5.5! Thanks In my example below, there are no elements that match, so you should see an alert box that says 'No match', but (using Firebug) you will see that an error is generated when it tries to find the value of onchange in the last input tag. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title></title> <script type="text/javascript"> function myLoad() { //Add some text beside the Zip/Postal Code box var _match = false; var _cell = 0; var _allnames = document.getElementsByName('zip_code'); //Get all the TD tags var _len = _allnames.length; //How TD tags are there? for (_j=0; _j<_len; _j++) { //Loop thru each child _nodetype = _allnames[_j].nodeType; _name = _allnames[_j].attributes.getNamedItem('name').value; _onchange = _allnames[_j].attributes.getNamedItem('onchange').value; _type = _allnames[_j].attributes.getNamedItem('type').value; _size = _allnames[_j].attributes.getNamedItem('size').value; if (_nodetype == 1) { if ( (_name == 'zip_code') && ( _onchange == 'zip_changed();') && (_type == 'text') && (_size == '10') ) { //Look for these specific things to get the correct node (INPUT tag in this case) _match = true; alert('Match found'); var _old_node = _allnames[_j]; //This is the INPUT tag we were looking for var _new_node = document.createTextNode(' Enter NONE if this does not apply'); //This is the text we will add on the end of it _allnames[_j].parentNode.insertBefore(_new_node, _old_node.nextSibling); //insertBefore inserts before the element, but using targetElement.nextSibling inserts it after instead (insertAfter is deprecated)!! } } } if (_match != true) { alert('No match'); } } </script> </head> <body onLoad="myLoad();"> <table class="zipncountry" border="1"> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> </table> <br> <table border="3"> <tr> <td>4<input type="hidden" value="" ></td> <td>5</td> <td><input type="text" name="zip_code" value="123" size=11 maxlength=20 onChange="zip_changed();"><input type="hidden" name=zip_code value="321" maxlength=20 ></td> </tr> </table> <br> <table class="zipncountry" border="5"> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> </table> </body> </html> Hello, I am trying to write a javascript page that shuffles an array of questions ( 1x1 , 1x2, 1x3 - 1x12), prints them, then has the user type in the answer, then checks them to make sure the user answer is correct. I have looked up a lot of source code for javascript "quiz" but they all are multiple choice answers and the questions are not shuffled. This is as far as I have gotten, but now I am not sure how to take the user input text and compare them to the answer / question array to make sure to check. Code: <html> <head> <title> Slick Math </title> <script type="text/javascript"> var quest = new Array; var ans = new Array; var questprint = new Array; quest[0] = "1 x 1 "; quest[1] = "1 x 2 "; quest[2] = "1 x 3 "; quest[3] = "1 x 4 "; quest[4] = "1 x 5 "; quest[5] = "1 x 6 "; quest[6] = "1 x 7 "; quest[7] = "1 x 8 "; quest[8] = "1 x 9 "; quest[9] = "1 x 10 "; quest[10] = "1 x 11 "; quest[11] = "1 x 12 "; questprint[0] = quest[0]+"<input type='text' name='q0'></input><br/>"; questprint[1] = quest[1]+"<input type='text' name='q1'></input><br/>"; questprint[2] = quest[2]+"<input type='text' name='q2'></input><br/>"; questprint[3] = quest[3]+"<input type='text' name='q3'></input><br/>"; questprint[4] = quest[4]+"<input type='text' name='q4'></input><br/>"; questprint[5] = quest[5]+"<input type='text' name='q5'></input><br/>"; questprint[6] = quest[6]+"<input type='text' name='q6'></input><br/>"; questprint[7] = quest[7]+"<input type='text' name='q7'></input><br/>"; questprint[8] = quest[8]+"<input type='text' name='q8'></input><br/>"; questprint[9] = quest[9]+"<input type='text' name='q9'></input><br/>"; questprint[10] = quest[10]+"<input type='text' name='q10'></input><br/>"; questprint[11] = quest[11]+"<input type='text' name='q11'></input><br/>"; var score = 0; ans[0] = 1; ans[1] = 2; ans[2] = 3; ans[3] = 4; ans[4] = 5; ans[5] = 6; ans[6] = 7; ans[7] = 8; ans[8] = 9; ans[9] = 10; ans[10] = 11; ans[11] = 12; function shuffle() { return (Math.round(Math.random())-.5); } questprint.sort(shuffle); </script> </head> <body> <h1>Slick Math</h1> <form name="form"> <script type="text/javascript"> document.write(questprint[0]); document.write(questprint[1]); document.write(questprint[2]); document.write(questprint[3]); document.write(questprint[4]); document.write(questprint[5]); document.write(questprint[6]); document.write(questprint[7]); document.write(questprint[8]); document.write(questprint[9]); document.write(questprint[10]); document.write(questprint[11]); </script> </form> </body> </html> Thanks =] Code: solved ! Hi all, I have some code that attempts to save a user's preference settings. It first tries to use "localStorage", and if that fails (only old versions of MSIE), then a cookie is used instead. I tried several different tests, such as: Code: if (localStorage) { alert('True'); } else { alert('False'); } and....... if (typeof localStorage).... and....... if (typeof localStorage == 'object').... but none of these are reliable. For example, if I intentionally misspell "localStorage" by instead using "localStor" (simulating a browser that doesn't understand the object name), the code simply does not run. What I ultimately want is this: Code: if (user_wants_to_save_settings && localStorage) { save_to_local_storage; } else if (user_wants_to_save_settings) { save_to_cookie; } ...unfortunately, that doesn't work. Anyone have ideas? I've been staring at this too long and am probably missing the obvious.... Thanks! -- Roger I am creating an assignment and cant seem to figure whats wrong with my code. I just need it to loop through three different radio buttons and test which is selected, then display an alert box based on it. here is my code: Code: function displayOrder() { // set var radio_choice to false var selected = false; var crustType = document.orderform.crust; var crust; // Loop from zero to the one minus the number of radio button selections for (var i = 0; i < crustType.length; i++) { // If a radio button has been selected it will return true // (If not it will return false) if (crustType[i].checked); selected = true; crust = crustType[i]; } if (!selected) { // If there were no selections made display an alert box alert("Please select a crust type.") return (false); } alert("you have selected " + crustType[i] + " crust pizza"); return (true); } } here is my html form: Code: <form name="orderForm"> Welcome back: <br /><br /> Please select your crust type: <br /> thin: <input type="radio" name="crust" value="thin"/> <br /> thick: <input type="radio" name="crust" value="thick"/> <br /> none: (?!) <input type="radio" name="crust" value="none"/> <br /> <input type="button" value="submit" onClick="displayOrder()" /> </form> Thanks a lot for the help I have the following regex pattern: var patt=/(&(?=(amp|apos|gt|lt|quot)|[^&])+/; It's validation to ensure that any ampersand sign is followed by amp;, apos;, gt;, lt;, or qout;. It should validate any other character except the aforementioned ampersand case. The regex checks out ok on all online regex testers. however, when i apply it to javascript via the test() method, things that return a fail in the testers return true with the js test() method, so the validation isn't working for me right now in javascript. e.g. var testStr = 'someString&'; //should fail var testStr2 = 'someString&'; //should pass however, calling patt.test(testStr); returns true when it should be returning false... Thanks for any input and help you all have to offer. I've been beating this to death for about 3 hours and I'm a little stuck on it.. I need a simple handy utility of some sort to test out the scripts while I am studying, any referrals please?
Hello, i Have problem about clear value when ppl input data on text field Any idea? Code: <form action="http://www.packagetrackr.com/track/" method="get" name="track" target="_blank"> <div class="form-field-error-message hidden" style="display: none; "> <div class="CommonEmptyTrackingNumber"></div> </div> <div id="track-form-tracking-number-container"> <div id="track-form-tracking-number-inner-container" class="track-form-control-boxer"><input id="track-form-tracking-number" class="track-form-element " type="text" name="n" value="Type a tracking number" title="Type a tracking number..." onFocus="if(/^Type a tracking number...$/i.test(this.value)){this.value='';}" onBlur="if(this.value==''){this.value='Type a tracking number...';}"> <input value="Track!" name="submit" type="submit" title="Track your package" class="track-form-submit-button sprite-master"> </div> </div> <div id="track-form-jss-carrier-container" class="hidden" style="z-index: 1000; display: none; "> <div id="track-form-jss-carrier-content"> <label id="jss-carrier-auto" class="track-form-jss-carrier-label jss-carrier-label"> <input id="jss-carrier-auto-value" value="" type="radio" name="c" checked="checked"> <span>Auto Detect Carrier</span> </label> </div> </div> </form> |