javascript code not working in firefox

Your code is far from being a proper XHTML document, but works in IE, since its really forgiving. A few things: the form elements should go in the form tag. Its only when they go inside the form tag, a name attribute given to them is valid, otherwise name attribute for non-form elements is deprecated.
The language attribute of tag is deprecated. Use 'type ' instead. Something like .
Its always recommended to place your script in the header section or include it at the bottom of your page.
The way you are accessing the elements is completely wrong. One possible way would be to just pass the form element to the validate function and let the function pull out values from the form. Something like this:
I would recommend you to get hold of a good tutorial (google is your friend) and start some serious reading., thanks got it working....
another thing, can you tell me how to get a login dialog box at the start i.e "on loading" of a page, Erm.. not using javascript. It's not a good way to adequately password protect pages. The best you can do with javascript is: - hide everything but the password form on the page (wrap everything in an html element, set display:none; or visibility:hidden; in css) unless the user enters the correct password (then set everything visible, using display:; or visibility:visible; respectively). unfortunately, everything on the page can be seen using view > source.
- have the page redirect when the user enters the correct password ( as you're doing here ); again, anyone can look at the source, and find out the URL of the restricted page.
- the best javascript 'password protection' i've seen did this: have a page with a password form; when the user enters anything in the password field; the script redirects to a folder with the name of the correct password; the basic principle is, that it's difficult for the average user to know where the folders on a webserver are, unless you give some hint ( links, common folder names, etc ). every incorrect guess will redirect to some unmapped location on your server; not ideal, but it restricts access. the bad point here, is that any user watching an 'admin' can see what the password-named folder is.. but, it's the best javascript password restriction method that I can imagine. You could take it a step further, and transform the password entered by some text/ascii math function before redirecting, but, the script suffers from the same vulnerability I mentioned if someone sees an admin login, although, its less obvious if the function generates some long non-dictionary string of characters. the real solution, is not to use javascript for password restriction. use some method server-side that only sends pages to users that are authorized. aswell as a good set of tutorials for javascript, some for basic server side authorization, and somewhere in there the client-protocol-server relationship, would be quite useful... If you want to go ahead with JS validation regardless of that advice, and you just want an input dialog to pop-up; this code _should_ do that:
I haven't tested it atall, but it looks alright, although it's old-school quirks mode HTML. It would need the same fixes as s.o.s mentioned with regard to your posted code in order to make it 'new standards compliant'

Posted On: Saturday 24th of November 2012 04:27:11 AM Total Views:  424
View Complete with Replies

Related Messages:

JS form not working in IE and Firefox   (265 Views)
Hi Guys, I'm trying to do up a contact form that after a user submits the information, the drop down contact box will slide back up instead of redirecting to another page. The script works fine in Chrome and Safari, but Firefox and IE keeps redirecting to the php page. Hope someone can shed some light here, thanks! Html form: Drop us a mail Name: Email Address: Message: Message sent successfully! //You should create the validator only after the definition of the HTML form var frmvalidator = new Validator("cform"); frmvalidator.addValidation("emailName","req","Please enter your Name"); frmvalidator.addValidation("emailName","maxlen=20", "Max length for Name is 20"); frmvalidator.addValidation("emailFrom","maxlen=50", "Max length for email is 50"); frmvalidator.addValidation("emailFrom","req","Please enter your Email"); frmvalidator.addValidation("emailFrom","email","Please enter a valid email"); Contact Details XXXXXXXXXXXX T: 999F: 999 Stalk Us   | Contact Us Close Panel   Slider JS: $(document).ready(function() { // Expand Panel $("#open").click(function(){ $("div#panel").slideDown("slow"); }); // Collapse Panel $("#close").click(function(){ $("div#panel").slideUp("slow"); }); // Switch buttons from " There | Contact us" to "Close Panel" on click $("#toggle a").click(function () { $("#toggle a").toggle(); }); //submission scripts $('div#panel').submit( function(){ //statements to validate the form var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; var email = document.getElementById('emailFrom'); if (!filter.test(emailFrom.value)) { $('.email-missing').show(); } else {$('.email-missing').hide();} if (document.cform.emailName.value == "") { $('.name-missing').show(); } else {$('.name-missing').hide();} if (document.cform.message.value == "") { $('.message-missing').show(); } else {$('.message-missing').hide();} if ((document.cform.emailName.value == "") || (!filter.test(email.value)) || (document.cform.message.value == "")){ return false; } if ((document.cform.emailName.value != "") && (filter.test(email.value)) && (document.cform.message.value != "")) { //hide the form $('.div#panel').hide(); //show the loading bar $('.loader').append($('.bar')); $('.bar').css({display:'block'}); //send the ajax request $.post('contactengine.php',{emailName:$('#emailName').val(), emailFrom:$('#emailFrom').val(), message:$('#message').val()}, //return the data function(data){ //hide the graphic $('.bar').css({display:'none'}); $('.loader').append(data); }); //waits 2000, then closes the form and fades out $("#messageSent").show("slow"); setTimeout('$("#toggle a").toggle(); $("div#panel").slideUp("slow")', 2000); //stay on the page return false; } }); }); PHP:
onmouseover is not working in chrome   (196 Views)
I am calling javascript from java and calling a function, and that function on an image i am calling onmouse over. So now the problem is, I have two jsp, secord inside first. when i click first jsp where is onmouseover, it's working fine and after that i am doing operation in second jsp and coming back on first jsp's image so onmouseover should be display but it's not working in chrome. Please if any one have idea log here.
[split] window.event.srcElement not working in FF?   (179 Views)
//This is my html code //this is javascript function for deleting a row function delRow() { var current = window.event.srcElement; //here we will delete the line while ( (current = current.parentElement) && current.tagName !="TR"); current.parentElement.removeChild(current); }
[ask] JQuery preventDefault is not working   (182 Views)
I want create a page which has animation at the bottom of that page. I use jQuery to do that.. this is the way I do it Animate this and this is the jquery $(document).ready(function() { $('a.animation').click(function(e) { e.preventDefault(); //animation goes here; }); }); When I run the code, all animation run very well except the page always scroll to the top. I try to change the href attribute tojavascript:void(0); but it still run like that.. How can I fix it
javascript for enable/disable button not working correctly   (346 Views)
Guys, So I'm making a webpage that has a form that is based on the selected section of the website... And I got a few questions/issues. Is it normal that I have to make a different name for a value from a section that needs a javascript (line 4-30 & 124 & 146 & 166 & 183 ) is there any way to do it simpeler and not have to add 2 times the same code can you give me some tips on how to simplify & minimalise the amount of code any other recommendation regarding this script I'm kind off a newbie in this, so any other tips are welcome!
document.getElementById not working in IE. Why?   (186 Views)
First a little background. I have a client (in-house) who insists that our training pages (launched from within iframes on a parent page) be able to load .wmv files with variables for the width and height parameters so we don't have to recode when videos are switched. Flash videos are not an option. I've searched the net and have received several suggestions and even code snippets from several sources but the only one that comes close to working is this one: window.onload=function(){ loadVideo(); } function loadVideo() { if (parseInt(navigator.appVersion)>3) { if (navigator.appName == "Netscape") { winW = window.innerWidth; winH = window.innerHeight; } if (navigator.appName.indexOf("Microsoft") != -1) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } } var dimW = winW-50; var dimH = winH-20; var w1 = dimW.toString(); var h1 = dimH.toString(); if(document.getElementById("vidEmbed") != null) { document.getElementById("vidEmbed").src = "Welcome_1.wmv"; document.getElementById("vidEmbed").style.width = w1; document.getElementById("vidEmbed").style.height = h1; } else if(document.getElementById("Player") != null) { document.getElementById("Player").style.width = w1; document.getElementById("Player").style.height = h1; document.getElementById("objectSrc").value = "Welcome_1.wmv"; } } Introduction I say close because it works just fine in Firefox (go figure) but doesn't appear to be working correctly in IE. IE just will not load the video using the "objectSrc" id. If I move the source video from the javascript into the actual object, then it loads and plays the video (it still doesn't resize the window correctly). I've been in several forums and have poured over the code with several people and we just can't figure out why this code doesn't work correctly. Can anyone here help
java script code inside ajax content not working   (190 Views)
Hi In my web page i am using tweetmeme button java script code.its working fine.When i was trying to put js code inside ajax content,and click the ajax callback button the entire page shows blank page.I thought the reason for this is java script using window.location.href.But i am not sure what is the exact reason for this issue. If i remove the tweetmeme button js code,ajax navigation button working fine. please help me to solve this issue.
Form button just stopped working   (159 Views)
, I'm having a problem understanding why would a form I built before would stop working now. Basically I have some javascript functions that are being called in a reservation form with 2 buttons. This is the JS code: var bgMemory; // save color information var fgMemory; var statusinfo = false; function mOver(cell, id, statustxt) { = 'hand';'#e6e6e6'; if (typeof document.getElementById(id + "cc") == "object") { Elem = document.getElementById(id + "cc"); bgMemory =;'#e6e6e6'; } if (typeof document.getElementById(id + "l") == "object") { Elem = document.getElementById(id + "l"); fgMemory =;'#3D6484'; } window.status=statustxt; statusinfo = true; return true; } function mOut(cell, id) { = 'hand';''; window.status=""; if (typeof document.getElementById(id) == "object") { Elem = document.getElementById(id + "cc"); = bgMemory; } if (typeof document.getElementById(id + "l") == "object") { Elem = document.getElementById(id + "l"); = fgMemory; } window.status=''; statusinfo = false; return true; } function mClick(cell) { if(event.srcElement.tagName=='TD') { cell.children.tags('A')[0].click(); } } var xMonths = new Array( 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ); function getListValue( option_object ) { return option_object.options[option_object.selectedIndex].value; } function setListValue( option_object, value ) { option_object.selectedIndex = value; } function addDays(myDate,days) { return new Date(myDate.getTime() + days*24*60*60*1000); } function init() { xToday = new Date(); yToday = addDays(new Date(),3); xMonth = xToday.getMonth(); xDay = xToday.getDate()-1; xYear = xToday.getYear()-2005; if (xYear < 2005) xYear=0; yMonth = yToday.getMonth(); yDay = yToday.getDate()-1; yYear = yToday.getYear()-2005; if (yYear < 2005) yYear=0; xF = document.forms['quickbooking']; setListValue( xF.ETAHour, 9 ) setListValue( xF.ETAMonth, xMonth ) setListValue( xF.ETADay, xDay ) setListValue( xF.ETAYear, xYear ) setListValue( xF.ETTHour, 9 ) setListValue( xF.ETTMonth, yMonth ) setListValue( xF.ETTDay, yDay ) setListValue( xF.ETTYear, yYear ) } function openhelp( hlpString ) { hlpWin = hlpString , 'Help', 'width=395,height=345,resizable=yes,scrollbars=yes,status=yes') hlpWin.focus(); } function doContinue( ) { xF = document.forms['quickbooking']; xETADay = getListValue( xF.ETADay ); xETAMonth = getListValue( xF.ETAMonth ); xETAYear = getListValue( xF.ETAYear ); xETAHour = getListValue( xF.ETAHour ); xETAMinute = getListValue( xF.ETAMinute ); xETA = xETADay + xMonths[ parseInt( xETAMonth )-1 ] + xETAYear.substr(2,2) + '/' + xETAHour + xETAMinute;xETTDay = getListValue( xF.ETTDay ); xETTMonth = getListValue( xF.ETTMonth ); xETTYear = getListValue( xF.ETTYear ); xETTHour = getListValue( xF.ETTHour ); xETTMinute = getListValue( xF.ETTMinute ); xETT = xETTDay + xMonths[ parseInt( xETTMonth )-1 ] + xETTYear.substr(2,2) + '/' + xETTHour + xETTMinute; xWizardNumber = xF.wizard_number.value; xName = xF.surname.value ; xRL_Country = xF.Country.value ; xParams = '&CTR=' + xCountry +'&Country=' + xCountry + '&ETA=' + xETA + '&ETT=' + xETT+ '&CNAM=' + xName + '&WIZ=' + xWizardNumber+'&SOR=0038780x'; url = '' + xParams;location.href = url; } window.onload = init; And this is the 2 buttons of the form: The "More Options" button is working fine but when I enter my email and click on "Continue" it doesn't do anything, if I leave the email field blank and click continue it works but poping the alertbox... Help would be really appreciated, thank you. I just realized that if you goto the page and you view the page's source, you'll notice in the javascript that there are 2 email validation functions and none of them is present in the actual file code (reservation-form.html)... I don't know where are they coming from.
timer not working!!   (171 Views)
ki ggt
javascript not working   (130 Views)
this is just part of the code. when i added the variable hide it stopped working. basically i want the php variable hide to add on to the variable newtext2. if i've implemented it wrong, need help correcting it. var newtext2 = obj( "reply" ).value; var hide =
onClick not working   (143 Views)
This code adds & removes textboxes from the screen. In the remove function, it also renames any textboxes that come after the one deleted so that the numbering stays in order (i.e. 1,2,3,4 instead of 1,2,4,5,8) and updates the count parameter of the textbox's corresponding remove link so that the textbox's name (i.e. file3) matches its count parameter. This is the line of code that appears to be causing me a problem: document.getElementById('removeLink' + nextFile).onclick = "removeAdditionalFile(this.parentNode, ' + count + ')"; in the while loop of the removeAdditionalFile function. Basically, the textbox doesn't get deleted like it should when you click on the link. My guess would be because "this.parentNode" isn't pointing to the right thing, but I don't understand why it's not. Anybody know how to fix this I had been fooling around for awhile with updating the entire innerHTML instead of just the onclick (in the while loop of the remove function), and it was kind of working but not quite and it was much more complicated, so if I could just get the onclick changed correctly, that'd be great. function addFileTextbox() { //main div that the other divs will be added to var divLocation = document.getElementById('addToDiv'); //create new div for holding textboxes, & give it a unique name for uploading var newDiv = document.createElement('div'); var count = document.getElementById('addToDiv').getElementsByTagName('input').length + 2; //+2 because since it hasn't been appended yet, the length will be short one. We need this number to set the unique div name. var divIDName = 'file' + count; var removeLinkID = 'removeLink' + count; newDiv.innerHTML = ' Remove'; //THIS WORKS FINE //Attach new div to main div location divLocation.appendChild(newDiv); //Increase the count of files to be uploaded (+1 for the file textbox already there) var fileCount = document.getElementById('addToDiv').getElementsByTagName('input').length + 1; document.getElementById('fileCount').value = fileCount; } function removeAdditionalFile(divIDNode, count) { //get main div that the other divs are attached to var divLocation = document.getElementById('addToDiv'); //delete the file textbox divLocation.removeChild(divIDNode); //Decrease the count of files to be uploaded (+1 for the permanent file textbox) var fileCount = document.getElementById('addToDiv').getElementsByTagName('input').length + 1; document.getElementById('fileCount').value = fileCount; //rename file textboxes that come after the one deleted so that they get uploaded var nextFile = count + 1; while (document.getElementById('file' + nextFile)) //there are file textboxes after the one deleted { //rename the file textbox to be one less & change the count parameter of the remove link document.getElementById('file' + nextFile).name = "file" + count; document.getElementById('removeLink' + nextFile).onclick = "removeAdditionalFile(this.parentNode, ' + count + ')"; //THIS DOESN'T WORK nextFile++; count++; //will always be one less than nextFile } }
OnClick/OnChange not working in IE   (236 Views)
I have a checkbox on click of which I'm calling a JavaScript function to disable another checkbox. The onClick event is not working in both Firefox/IE. I am capturing onChange event of the checkbox1 as of now which works in Firefox, but not working in IE. Please suggest a way to implement this. This is urgent. Thanx.
AJAX and stylesheets developed for IE not working?   (213 Views)
Hi ALL, We have developed some HTML pages code using AJAX and we have used some style sheets. This works fine in IE but the style sheets used are getting distracted Firefox as well as the AJAX calls are not working in Firefox. Please help.
why this is not working   (127 Views)
hi i wrote a simple ajax script its working and i don`t know why can any one here can help me when we place a mouse on a link then it shows that page this is my basicajax.php page ajax praveen kumar goud and this is my script.js file window.onload= init; var xhr=false; var xpos,ypos; function init(){ var alllinks=document.getElementByTagName("a"); for(var i=0;i
onclick problem in IE, working in FF/other   (208 Views)
! I am trying to make an image gallery navigation work in IE (works in FF2+, safari, not working in opera 9, probably other browsers) but my severely limited Javascript knowledge is really holding me back! I am using JonDesign's SmoothGallery (camelback heaven, there), but the problem almost certainly lies in my rouge implementation of onclicks. The website in question is , but here is the code that is occasionally functioning (ignore the class and mouseovers): I've also tried, to no avail: There is also a thumbnail gallery that calls individual images, as follows, though I'm sure the problem is the same as the problem with the above code: Lastly, here is the script: function startGallery() { myGallery = new gallery($('myGallery'), { timed: false, showCarousel: false, showInfopane: false, showArrows:false, slideInfoZoneSlide: false, delay: 3500 }); } window.addEvent('domready',startGallery); In any case, this seems to work in about half the browsers I've tried, which makes me think that maybe my code is pretty close but I'm off a bit with my syntax or something. The linked javascript file is at and the original gallery is at , but I'm hoping the answer is glaringly obvious.
Anyone see why this isn't working for IE?   (141 Views)
all Can anyone see why this isn't working for IE but is Firefox I'm trying to update a div on the page using some javascript and php. Whenever a dropdown box on the html page is changed, its value is passed to a javascript function, then onto a php file. The php file runs and javascript updates the div. HTML Code: Indoor Outdoor Sand Javascript Code: var xmlhttp; function updateTourns() { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url = "include/js/tournSearch.php"; url = url + "in_out_door1=" + document.getElementById('in_out_door').value; url = url + "&class1=" + document.getElementById('class').value; url = url + "®ion1=" + document.getElementById('region').value; url = url + "&level1=" + document.getElementById('level').value; url = url + "&year1=" + document.getElementById('year').value; url = url + "&sid=" + Math.random(); xmlhttp.onreadystatechange=stateChanged;"GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) document.getElementById("tourn").innerHTML=xmlhttp.responseText; } function GetXmlHttpObject() { if (window.XMLHttpRequest) return new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5 return null; } Finally, tournSearch.php $in_out_door = $_GET['in_out_door1']; $class = $_GET['class1']; $region = $_GET['region1']; $level = $_GET['level1']; $year = $_GET['year1']; echo $in_out_door . ", " . $class . ", "; In Firefox whatever was selected from the dropdown box is echo'd. This does not happen in IE. Thank you!
Spry menu not working in IE   (332 Views)
Can anyone help me I tried using spry in dreamweaver CS3 for the first time and, upon completion of my site, found that it isn't working in some versions of IE. It opens perfectly in Firefox, Safari, and Opera. Different versions of Internet Explorer seem to carry out the code differently. Here is my site And my css and my javascript If ANYONE could look over my code and help me I would really appreciate it!! PLEASE!!
Ajax.PeriodicalUpdater (Prototype) not working with?   (175 Views)
I'm trying to use Prototype's Ajax.PeriodicalUpdater to scroll through/display an array of items on an interval. So far I've managed to make it display a new item every 2 seconds, but it only works in Firefox. Haven't tested in Safari or Opera yet...but I know it doesn't work in IE6. It can be seen below here: on the index.php page, I have this script written: Event.observe(window, 'load', function() { new Ajax.PeriodicalUpdater('comment_slider', 'comment_slider_ajax.php', { method: 'post', frequency: 2, onSuccess: function(){ new Effect.Fade('comment_div', { duration:0.3 }) }, insertion: 'top', }); }); function showComment(divId){ new Effect.SlideDown(divId, { duration:0.3 }); } showComment() is called in comment_slider_ajax.php, which displays the "comment_div" and calls the showComment() function. I've searched through some similar issues -- some people seem to experience it, but others confirm that it's working. I've seen some users say that the object only fires the AJAX request once, then stops working. Anyone have any ideas
AJAX snippet not working with Firefox   (131 Views)
hello people, here is a piece of AJAX that i have used in my JS file. It's working fine with IE but somehow the page does not load in Firefox. function secondRead(){ if(xmlHttp.readyState == 4){ if (xmlHttp.status == 200) { try{ var status = xmlHttp.responseText; alert(status); status = status.split(":")[0]; status = status.split("ment ")[1]; if(status == "Success"){ htmlResponse = " Your transaction was successful. Congratulations, Your E-Commerce trainer will contact you within 1 business day. Please take a moment and fill out the survey below, so we may know how to serve you better. 1. What do you currently do for a living Which best describes your industry   -----Business----- Agriculture, Fishing and Forestry Broadcast/Cable/Tv/Radio Construction Engineering and Management Graphic Design Insurance Legal Manufacturing Media/Entertainment/Arts Mining Non-Profit/Charity Other Industry Printing and Publishing Professional Services (Business) Professional Services (Technical, Web, IT) Real Estate Retail/Wholesale/Trade Services Technology/High Tech Telecommunications Transportation Utilities -----Creative----- Advertising Architecture Film/Video/Animation Production Membership OrganizationPhotographyPublic Relations-----Education-----Education - Higher EdEducation - K-12-----Government-----Government - FederalGovernment - Military/Aerospace & DefenseGovernment - State/Local-----Other-----Other-----Life Sciences-----Health CareHospitality and Food ServicesPharmaceutical/Biotech2. What is your age   Less Than 25 25 - 50 Above 50 3. What is a suitable time to contact you   Before 12 noon Between 12 pm and 5 pm After 5 pm 4. How Much Debt Are You In   Less than $10,000 Between $10,000 and $50,000 Between $50,000 and $100,000 More than $100,000 5. How Motivated Are You To Succeed   Not that motivated Slightly! Some extra cash would be nice Very Motivated! I need more money FAST Extremely Motivated! I am in debt and at RISK 6. How Much Time Can You Dedicate To Making Money Online   Just 1-hour per week 5-hours (1-hour per day) 10-hours (2-hours per day) 20-hours (4-hours per day) 7. If You Are Selected To Work With Our Team, How Committed Are You to Using Our Training Program Please Select One   I am not really that interested but I will at least see what all the fuss is about I think this might work for me. I am willing to try anything once I am 100% committed 8. If you are selected, what would your goals be   I would like to quit my job and work from home I would like to get out of debt I want to secure my financial future "; } else if(status == "Failed"){ htmlResponse = " There was a processing error, please click the home button and try again. "; } document.getElementById("main").innerHTML = htmlResponse; } catch(err){ alert("!!!"); } } } }//end of secondRead() it could be something about the split() used here. please have a look and let me know ASAP.
alert(xmlHttp.responseText) not working   (162 Views)
i want to get the alert on responce text, but getting nothing, my code is as follow, var xmlHttp function checkCAP(str) { if (str=="") { alert("plase enter the code"); return } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="test.php" url=url+"id="+str xmlHttp.onreadystatechange=stateChanged"GET",url,true) xmlHttp.send(null) } function stateChanged(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { var response = xmlHttp.responseText; if( response == "incorrect"){ alert(Please enter the right words); } } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } Securimage Test Form