JavaScript - Weird Problem?
Hello guys,
I'm currently writing an web application using java servlets and javascript. Today i ran into this weird problem. The servlet sends to the client an html page which has an javascript in it and a form. Upon completion of the form and pressing the submit button the javascript does not execute(but the form is sent, function is called with the onclick tag). If i view-source this page from my browser and save it to an .html file locally the javascript function executes just fine. Any help greatly appreciated Similar Tutorialsso my code is Code: function more(){ alert("You can't eat more apples then you have"); } function apple(){ var apples = prompt('How many apples do you have'); var eat = prompt('How many did you eat'); if(eat > apples){ more(); } if(eat <= apples){ var eaten = apples - eat; alert('You ate '+ eaten + ' apples!'); } } My problem is unless you enter 1 for how much did you eat, it goes to the more function. Some people claim that the window.onload does not fire in some browsers, under some OS, when the page is re-loaded using the back button of the browser. The simple code is: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script type="text/javascript"> onload=function(){ alert('foo') } </script> </head> <body> <a href="http://www.google.com">go Google then press the back button</a> </body> </html> Open the document, click the link, then press the Back button of the browser. Surprisingly, in FF 3.6.3 (at least) the window.onload event is not read again, thus it does not fire the function. That is a severe issue, as a lot of JavaScript codes are based on onload event. Is it a bug? Does that happen only locally (I can not test it on a server this moment)? Are there any other browsers or other browsers' versions which act in the same way? Any thoughts? Hello there, Problem: I was able to see problem only in IE6 Form input fields not clickable and not accepting inputs + Can't even select text or perform most right-click functions. URL: http://www.webhostingkit.com/a/cgi/p...usercontactall Was wondering if anyone can help me out with this weird problem. Not sure why, but none of the input form fields are able to accept values or even clickon them. Site displays just fine in IE, however anywhere on the site, when user tries to input, it just won't show happen, any idea on what is wrong or how to fix this? Thanks again. ** Edit ** If anyone has IE6 installed can you please test it, cuz I am thinking it might be just the standalone version of IE I have might be having the issue, as in that IE, some major sites (including yahoo.com) are having the same issues. For some reason i cant get this bit of code to work. You can ignore the php and html if its getting in your way. Thanks: Code: <div id="pl"> <? if($edit == true){ ?> <script type="text/javascript"> $("#add_playlist_form").css({display:"none"}); $("#add_playlist").click(function(){ alert($("#add_playlist").html()); if($("#add_playlist").html() == "Add a Playlist >>"){ $("#add_playlist").html("Hide <<"); $("#add_playlist_form").css({display:"block"}); } else{ $("#add_playlist").html("Add a Playlist >>"); $("#add_playlist_form").css({display:"none"}); } }); </script> <a href="#" id="add_playlist">Add a Playlist >></a> <form id="add_playlist_form" method="POST" action=" "> <input type="text" name="pl_name" class="add_playlist"/> <textarea name="pl_dsec" maxlength="200"></textarea> <input type="submit" name="submit_playlist" value="Add Playlist" class="submit_playlist"/> </form> <? } ?> <ul class="vList"> I am new here. I've been trying to learn javascript, php, ajax, and others on my own, through the help of researching. I can't seem to manage figuring this out. I'm using a string "A B C" for sake of example. Variable d goes through a for loop checking for capital letters, to make substrings. d=0 finds A and makes the substring A. d=1 finds B and makes the substring AB. d=2 finds C and makes the substring ABC. It seems to me that: d=0 should be A d=1 should be B d=2 should be C. (which is what I want) Here's the actual code (obviously, the actual string being worked with is not 'A B C'): Code: response = response.replace(/([A-Z])(?![A-Z])/g, " $1") ; response1 = new Array(); caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; a=0 ; q=0 ; for (a=0 ; a<=response.length-1 ; a++) { for (q=0 ; q<caps.length ; q++) { if (response.charAt(a) == caps.charAt(q)) { response1[response1.length] = response.substring(a,' ') ; }}} response1 = response1.filter(function(){ return true}) ; b=1 ; for (b=1 ; b<=response1.length-1 ; b++) { document.write(response1[b] + "<br />") ; } } Hi folks, I'm updating code that's been in use for years now. Consider the following: Code: <script language="javascript"> function submitForm() { frm.submit(); } </script> ....//body tag, etc <form name="frm" action="blahblah"> //button here that calls submitForm() on click; </form> This is, of course, a highly stripped down version but you get the idea. The problem, this site was not a standalone site before, i.e. www.mysite.com, but was in a subdirectory of our intranet. We've since upgraded it to ColdFusion 8 and made it a standalone site. frm.submit() no longer works and required us to change it to document.frm.submit(). Any ideas why? So I have the following code in javascript that creates an iframe: Code: var iframe = document.createElement("iframe"); iframe.id = 'offerframe'; iframe.name = 'offerframe'; iframe.width = '975'; iframe.height = '650'; iframe.align = 'center'; iframe.src = 'http://example.com'; document.getElementById("offer-frame-div").appendChild(iframe); It works fine in Firefox and Safari but in IE8 it generates the iframe name attribute to "submitName" Code: <iframe width="975" height="650" align="center" id="offerframe" submitName="offerframe" src="http://example.com"> Notice how it sets all the other attributes fine, however the name attribute is now called "submitName". This issue only happens in IE. This there any alternatives to setting my iframe name dynamically with javascript. Now this is really stumping me otherwise i wouldnt be here. I have a Javascript that i have that runs in a php site, i have a section where i can save the code to a part in my admin section for loading special images in diffrent locations. So i used java script for rotation on those images. The funny thing is it loads up in a few pages where it calls the php code. but in other pages it doesnt load anything at all. The call function works. in all pages but where the javascript doesnt work the static image i can place works. But i need it to use the javascript code so i can rotate them aswell. For example: Code: <div id="footads"> <div id="fad"> <? echo $foot1 ?> </div> <div id="fad2"> <? echo $foot2 ?> </div> <div id="fad1"></div> </div> the $foot1 and 2 are footer call function which pulls the java script. I have no problem running multi versions of this script as i change the vars etc in java to make them run. How ever like i said its not loading in some pages. but others it will? here is some linked examples. Working - Default advert images set on 10 sec delays Working diff page - Default advert images set on 10 sec delays not Working - Default advert images set on 10 sec delays Its like its not calling the code from the function, But it is because if you view source. Quote: <div id="footads"> <div id="fad"> <script language="JavaScript" src="/adverts/addbanner1.js" type="text/javascript"></script> <div class='addbanner1'><div id='addbanner1'></div></div><div style="clear:both;"></div> </div> <div id="fad2"> <script type= "text/javascript" src="/adverts/addbanner2.js" type="text/javascript"></script> <div class='addbanner3'><div id='addbanner3'></div></div><div style="clear:both;"></div> </div> <div id="fad1"></div> </div> Code: <html> <script> function doit(){ document.write(document.getElementById('myIMG').getAttribute('src')); } </script> <body onLoad="doit()"> <img src="blabla.jpg" id="myIMG"> My question is, why is it, that after loading the page, the image that should be displayed at the page is not being displayed. The only thing that can be seen is text generated by the document.write function. Hey, I've written a function that slides in a sidemenu when hovering over a div. The function is working great, but i need to "disable" the slide part when the menu is already visible. So i added an if statement and a global bool. (menuactive) My Problem Is: Even if menuactive is false the function will still run as if menuactive was true?? Code: $(document).ready(function(){ var menuactive = false; $('.nav_left').mouseover(function(){ if(menuactive = false){ $(".nav_left_menu").show(); $(".nav_left_menu").animate({ width: '164px' }, 400); $(".nav_left_menu ul").animate({ opacity: '1.0' }, 800); menuactive = true; } else{ alert("Menu is already visible!"); return; } }); }); Thanks, Hello guys, My script is used to check some text field before the user upload some text, below you can see the code: Code: // JavaScript Document function Check() { var no_error=true; var pattern=/^[A-Za-zΑ-ΩΆΈΉΊΌΎΏα-ωάέήίόύώ!%()-:,.;(\s)]$/; //oi xaraktires p dikaioute na eisagei o xristis--> http://www.evolt.org/node/36435 txt_quote=document.getElementById('add_quote').value; if(txt_quote.length>0 && txt_quote.length<2000) { for(var i=0;i<txt_quote.length;i++) { if(!txt_quote.charAt(i).match(pattern)) { document.getElementById('add_quote').style.backgroundColor='#FF3333'; no_error=false; } else { document.getElementById('add_quote').style.backgroundColor='white'; } } } else { //is bigger than 2000 characters or is null document.getElementById('add_quote').style.backgroundColor='#FF3333'; no_error=false; } txt_quote=document.getElementById('add_name').value; pattern=/^[A-Za-zΑ-ΩΆΈΉΊΌΎΏα-ωάέήίόύώ!%()-:,.;]$/; //No space if(txt_quote.length>0) { for(var i=0;i<txt_quote.length;i++) { if(!txt_quote.charAt(i).match(pattern)) { document.getElementById('add_name').style.backgroundColor='#FF3333'; no_error=false; } else { document.getElementById('add_name').style.backgroundColor='white'; } } } else { document.getElementById('add_name').style.backgroundColor='#FF3333'; no_error=false; } txt_quote=document.getElementById('add_links').value; pattern=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; // if(txt_quote.length>0) { if(!pattern.test(txt_quote)) { document.getElementById('add_links').style.backgroundColor='#FF3333'; no_error=false; } else { document.getElementById('add_links').style.backgroundColor='white'; } } else { document.getElementById('add_links').style.backgroundColor='white'; } return no_error; } function countChars() { var text=document.getElementById('add_quote').value; document.getElementById('count_characters').innerHTML=text.length.toString() + " από 2000"; if(text.length>2000) { document.getElementById('add_quote').style.backgroundColor='#FF3333'; } else { document.getElementById('add_quote').style.backgroundColor='white'; } } function restore_color(id) { document.getElementById(id).style.backgroundColor='white'; } function restore_color_to_all() { document.getElementById('add_quote').style.backgroundColor='white'; document.getElementById('add_name').style.backgroundColor='white'; document.getElementById('add_links').style.backgroundColor='white'; document.getElementById('add_quote').focus(); } After that i call the check() function like this Code: ...onsubmit="return Check()"> This script works just fine with internet explorer but it doesnt work with chrome or firefox. Any ideas? (i guess something is wrong since internet explorer works and chrome/firefox not ) Hi, I used the code on the following example: http://www.w3schools.com/php/php_ajax_livesearch.asp Instead of xml I use mysql but it works the same way. My problem is with this character '#' (shift 3 - on my keyboard, or otherwise known as 'sharp'). Some of the words in my database table contain this character but when I type it, it acts like nothing was typed. Any idea on what to do to make this work like any other character? Thanks I use this code to clone an object. At the end I test the properties: Code: //cloning codes function Clone(){} function clone(obj) { Clone.prototype = obj; return new Clone(); } // var Orange={natu 'fruit',color:'orange'} var Banana=clone(Orange); for(a in Banana){ alert(a) } So far so good. I see: nature - > color But now I want to change a property of the Banana object, the color, then test again the properties: Code: Banana.color='green'; for(a in Banana){ alert(a) } Surprisingly, the changed property becomes the first in the loop, which is curious. I see now: color - > nature Can anyone explain me why? I understand that the last new created property comes always first (which I don't like, but I take it as it is), but I suppose that, in the case above, the property was already defined, and I did nothing but changing its value. Is there a way to keep the order within the prototype? Hey guys. I have a weird issue (you kind of have to see it for yourself to understand). If you double click on the next or previous button quickly (within 500 miliseconds of each other) it creates a double of the next slide. http://insidehb.com/imageofday/ Let me know if you can help. Thanks. Find it really hard to understand these random variable names and what they are doing, can anyone explain what is going on exactly in the bolded parts. I have a rough idea but the 3 arrays confuse me somewhat im sure the random variable names are pointers and counts but id love to hear an expert explain them for sure thanks if you can help or are willing to take the time This might be a little complicated. I'll try to be as clear as possible. I got some help from Old Pedant a little while ago and the code worked great. The problem came after I tried some code that will highlight (select) text in a DIV: Code: <script type="text/javascript"> function selectNode (node) { var selection, range, doc, win; if ((doc = node.ownerDocument) && (win = doc.defaultView) && typeof win.getSelection != 'undefined' && typeof doc.createRange != 'undefined' && (selection = window.getSelection()) && typeof selection.removeAllRanges != 'undefined') { range = doc.createRange(); range.selectNode(node); selection.removeAllRanges(); selection.addRange(range); } else if (document.body && typeof document.body.createTextRange != 'undefined' && (range = document.body.createTextRange())) { range.moveToElementText(node); range.select(); } } </script> Code: <div id="bb1"></div> <form> <input type="button" value="Click Here to Highlight Data" onclick="window.selectNode(document.getElementById('bb1'));" style="margin-left:4px; font-weight:bold; font-family: Verdana, Arial, Helvetica, sans-serif; font-size:14px;"> </form> It works great with Firefox and Internet Explorer, but there is a problem with Opera. The contents of the DIV is selected, but so is everything after the DIV. Below is a link to the page, but be sure to turn down your speaker volume before you visit the page so you won't have a heart attack: http://www.randomterrain.com/atari-2...music-toy.html The DIV is empty when the page loads. To put content in the DIV, jump down to All Sounds and left click on a couple of the numbers than run from 0 to 31, then jump down to the DIV. When you click on the "Click Here to Highlight Data" button, you'll see that more than the contents of the DIV is selected. I hope someone can figure out how to make the code work properly with Opera. Thanks. So i have this weird problem that only occurs in IE, in combination with Adsense. I also tried FF and Chrome and it does not occur in those browsers. I use javascript to swap around divs, since css 'order' is not supported in every browser (at least not working for my iphone 4). The swapping is working fine in IE when you resize from a screen larger than 1024 to a screen smaller than 1024 and then to a screen larger than 1024. However it does not work well when you open the page/script in a screen smaller than 1024 and then make it larger (in IE). The sidebar 'aside' stays on the right side after 'article' instead of moving to the left. This only happens when i use adsense in the sidebar.. Otherwise it all works fine... Very weird to me.. Anyone who can help out? See this weird problem he JS Bin Here is the code: Code: <html> <head> <style> html, body { padding: 0; margin: 0; background: #eee; } body { padding: 0 3% } header, footer, .slogan, .page-wrapper, .headline-wrapper, aside, article { box-sizing: border-box } .slogan, aside, article { background: #fff } aside, article { padding: 20px; border-radius: 10px; margin: 10px 0 0 0; -webkit-box-shadow: 0px 0px 2px 0px rgba(50, 50, 50, 0.5); -moz-box-shadow: 0px 0px 2px 0px rgba(50, 50, 50, 0.5); box-shadow: 0px 0px 2px 0px rgba(50, 50, 50, 0.5); } header, footer { padding: 20px } @media (min-width:1024px) { .page-wrapper, header, footer { width: 100%; margin: 0 auto; max-width: 1200px; } .page-wrapper { display: table; width: 100%; padding-top: 50px; max-width: 1200px; margin: 0 auto; } .page-wrapper > aside, .page-wrapper > article { display: table-cell; padding: 20px; } .page-wrapper aside { width: 30% } article { position: relative } .slogan { padding: 0 20px; border-bottom: 0px; width: 100%; margin: 0; line-height: 50px; height: 50px; position: absolute; left: 0; top: -50px; } .slogan { border-radius: 10px 10px 0 0; -webkit-box-shadow: 0px -2px 2px 0px rgba(50, 50, 50, 0.3); -moz-box-shadow: 0px -2px 2px 0px rgba(50, 50, 50, 0.3); box-shadow: 0px -2px 2px 0px rgba(50, 50, 50, 0.3); background: #ddd; } article { border-radius: 0 0 10px 0 } aside { border-radius: 10px 0 0 10px } } </style> <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script> <script type='text/javascript'> function handleMargins() { var width = (window.innerWidth > 0) ? window.innerWidth : screen.width; if(width < 1024) { $(".page-wrapper").each(function() { var detach = $(this).find("aside").detach(); $(detach).insertAfter($(this).find("article")); }) } if(width >= 1024) { $(".page-wrapper").each(function() { var detach = $(this).find("article").detach(); $(detach).insertAfter($(this).find("aside")); }) } } jQuery(document).ready(handleMargins); $(window).resize(handleMargins); </script> </head> <body> <header>header</header> <div class="page-wrapper"> <aside> sidebar <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- N_Responsief_Alle_CTR_AlleAdsenseSites --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3961745091197220" data-ad-slot="3968514626" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script></aside> <article> <h3 class="slogan">One line slogan only </h3> <p>This is the articlediv</p> </article> </div> <footer>footer</footer> </body> </html> Reply With Quote 12-23-2014, 03:35 PM #2 sunfighter View Profile View Forum Posts Senior Coder Join Date Jan 2011 Location Missouri Posts 4,830 Thanks 25 Thanked 672 Times in 671 Posts You need a doctype! maybe add <!DOCTYPE html> at the top of this code. IE needs a doctype or it is screwy. hey guys, so on the website www.marcsnyderlaw.com how come it automatically redirects to # at the end of each link? Is there a way to remove that?? Thanks Hi pals, I am really tired in this problem of event keyup. I given same in my keyup function like: $(document).ready(function () { alert("GGG"+parseInt(jQuery.browser.version)); //To display test value working $("#find_text").keyup(function(e) { if(e.which == 13) { alert('Enter key was pressed'); //enter Here alert("FFF"+parseInt(jQuery.browser.version)); //Here got Error } }); }); I got Error : jQuery is not defined alert("FFF"+parseInt(jQuery.browser.version)); I use keycode,which , but no help, It's Work nicely in Chrome Browser but not in FF. Please give a Solution reply ASAP, I am really Tired.The code enter the Condition But that jQuery part make error. Thankfully Anes P.A Hi, I have html variable as below: html += "<div class='quickSearchResultDivUnselected' style='width:" + divWidh + "px;max-width:" + divWidh + "px'><a href='#' OnClick='javascript:test('" + title + "')>" + title + "</a></div>"; The problem is with OnClick='javascript:test('" + title + "')>". How to make this link as <a OnClick='javascript:test("VALUE")'></a>, because now as result it looks like this and it doesn't work: <a OnClick='javascript:test('value')'></a>; So the problem is with ' and ". How to make it correctly in this long line of html variable ? Please help. |