Hello I'm trying to change a basic login script to work so that if a promotion code is entered into the password box then using show/hide layers, the correct code changes which layer is showing. I've put it up at: http://www.testingpages4302.netfirms.com/loginscript.html with some words of explanation. The Password is password, but that means very little at the moment. Any help with this will be greatly appreciated. thanks - mika
Is there a reason you can't replace line 125's location="Anypage.html" with MM_showHideLayers('Layer1','','hide','Layer2','','show')? Also, if you're using a password box because you want security, embedding the proper password in the page itself might not be a good idea. Where you have <div class="form"><form name="login">Login: <input name="id" type="text"> Password:<input name="pass" type="password"> <input type="button" value="Apply Code" onClick="pasuser(this.form)"> </form></div> Code (markup): change to <div class="form"> Password:<input name="pass" type="password"> <button onClick="pasuser(this.form)">Apply Code</button> </div> Code (markup): If you're not submitting data you shouldn't need the form at all, and the login section should be fully removable. Since it's no longer a form, it might be better for readabilty to rename the div.
Thanks a lot James. I appreciate you taking the time to help me. I know it is not very secure - security isn't that important on this one. Where you say "the login section should be fully removable" in your response is where I'm unstuck again. Any attempt I've made to remove the login part stops the password working. I remade the page as per instructions and it is up at: http://www.testingpages4302.netfirms.com/loginscript.html and put some comments up there. If I can remove the Login part I'll be over the moon. Any help, once again, greatly appreciated. mika
This version works when I run it in IE on my desktop. I removed the form and all references to it in the pasuser function. <SCRIPT language=javascript> <!--// function pasuser() { if (document.all.pass.value=="password") { MM_showHideLayers('Layer1','','hide','Layer2','','show') } else { alert("Invalid Code") } } function MM_showHideLayers() { //v6.0 var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; } obj.visibility=v; } } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </SCRIPT> <DIV class=whatIwant> <P align=left>Now it works just fine.</P> <P align=left>If you enter password in the Password box and click on Apply Code then Layer 2 is shown.</P> <P align=left>I can't figure out how to remove the Login section. Removing<BR><STRONG>if (form.id.value=="")</STRONG> from the javascript doesn't do it, and if I remove <BR><STRONG><form name="login">Login: <input<BR>name="id" type="text"></STRONG> from the body the pass code no longer works. <BR></P></DIV> <DIV class=section> <DIV id=Layer1> <P>Price = $100.00</P> <P>This is Layer 1 </P> <P></P></DIV> <DIV id=Layer2> <P>Price = $90.00 </P> <P>This is Layer 2 </P> <P> </P></DIV></DIV> <DIV class=form> Password:<INPUT type=password name=pass> <INPUT onclick=pasuser() type=button value="Apply Code"></DIV> Code (markup):
Also, it looks like your page is including an external login script. It might be that it's wanting to play around with the password field. If that version doesn't work, try changing the name of the password field to "enteredCode" or something else meaningful but that's unlikely to be looked for by an external script.
Thanks once again James. Using the code you provided I made the page again and posted it at this new link: http://www.testingpages4302.netfirms.com/loginscript2.html It works fine in IE and Safari but in Firefox it doesn't work at all, the invalid code message doesn't even pop up. I tried changing the name of the password field but that made no difference. Again, any help in nailing this down will be gratefully received and will result in a little dance around the room. mika
I tested it with FF2 and it seems to be working fine. ("Invalid Code" message does pop up.) The FF2 javascript console is displaying a small warning, you might want to take a look at that, but other than that it seems to be working fine... (Warning: Non-standard document.all property was used. Use W3C standard document.getElementById() instead. Source File: file:///C:/Test/jscr_test.html Line: 5)
Thanks for checking it for me, but it still doesn't work in firefox for me. I've tried it on two computers with no joy. IE and Safari are fine still. Any ideas gratefully received. mika
It was really easy... Replace this if (document.all.pass.value=="password") { Code (markup): with this: var passbox = document.getElementById("pass"); if (passbox.value=="password") { Code (markup): Then replace this Password:<INPUT type=password name=pass> Code (markup): with this: Password:<INPUT type=password name=pass id="pass"> Code (markup): Let me know if it works for you...
Thanks a million. Worked like a charm. Working version is at: http://www.testingpages4302.netfirms.com/loginscript2.html Not too sure about easy, it is way beyond me and I'm very grateful to you guys for helping me out. Many cheers - rigbee
When i said it was working with FF2, i meant the code from James, i didn't even see your page. Later when you said it's still not working, i got curious how that could be, but then i realised you were talking abour your page which indeed wasn't working in FF2 when i checked it. After that, it wasn't too hard to track down what's wrong. You're wellcome