SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with JS code. Works in FF but not in IE

    I have a input field (text) which I want to add extra security for, so the user has to type his password if he wants to edit the field.

    Code:
    function makeWritable() {
    	var pwd=prompt("Enter your password to edit build no","");
    	
    	if (MD5(pwd) == "<?php echo md5($_SESSION['password']); ?>") {
    		document.getElementById("davit_bn").readOnly=false;
    	} else {
    		alert('Wrong password');
    		document.getElementById("davit_bn").readOnly=true;
    	}
    }
    This works in Firefox, but not in Internet Explorer. The code is placed in the head of html.

    In IE the prompt box appears, and if I enter wrong password I get the alert. But I cannot edit the field if I enter the correct password...

    Any thoughts of why?

    Thanks for answers.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This test script works fine for me in FF and IE6.
    Code javascript:
    function doSubmit(frm){
    	if(frm.sex[0].checked == true)
    		document.getElementById('myval').readOnly = false;
    	else
    		document.getElementById('myval').readOnly = true;
    }
    HTML Code:
    <form name="frm1" id="frm1">
    	Sex : <input type="radio" name="sex" value="Male" /> Male <input type="radio" name="sex" value="Female" /> Female
        <br>
        <input type="text" readonly name="myval" id="myval" />
        <br>
    	<input type="button" name="submit" id="submit" value="Submit" onClick="doSubmit(this.form);" />
    </form>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually.. it worked from the beginning.

    My mistake...

    Thanks anyway!

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajug View Post
    This test script works fine for me in FF and IE6.
    Code javascript:
    function doSubmit(frm){
    	if(frm.sex[0].checked == true)
    		document.getElementById('myval').readOnly = false;
    	else
    		document.getElementById('myval').readOnly = true;
    }
    That could be reduced down to one line:

    Code javascript:
    function doSubmit(frm){
    	document.getElementById('myval').readOnly = !frm.sex[0].checked;
    }

    I think this is the wrong thread though.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •