PDA

View Full Version : Masking the text in a javascript prompt box


CBrown
11-22-2004, 11:33 PM
How would I mask the text entered into a javascript prompt box?

coothead
11-23-2004, 08:43 AM
Hi there CBrown,

you cannot style dialogue boxes :supereek:

You can, however, make imitations like this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>imitatation prompt</title>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<base href="http://achelous.mysite.wanadoo-members.co.uk/"/>

<style type="text/css">
/*<![CDATA[*/

#prompt {
position:absolute;
width:488px;
height:125px;
background:url('prompt.jpg') no-repeat;
display:none;
}

#ok {
width:75px;
height:22px;
margin:32px 0px 0px 399px;
}

#cancel {
width:75px;
height:22px;
margin:6px 0px 0px 399px;
}

#password {
width:460px;
font-size:16px;
margin:4px 0px 0px 14px;
}

/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[

var t=(screen.height-125)/2;
var l=(screen.width-488)/2;

var df=document.forms;
var obj;

function fakePrompt() {

obj=document.getElementById("prompt");

obj.style.top=t+"px";
obj.style.left=l+"px";
obj.style.display="block";
df[0][2].focus();

}

function OK() {

info=df[0][2].value;
obj.style.display="none";
alert(info);
df[0].reset();

}

function shut() {

df[0].reset();
obj.style.display="none";

}

//]]>
</script>

</head>
<body>

<div>
<a href="javascript:void(fakePrompt())">get information</a>
</div>

<div id="prompt">

<form action="">
<div>

<input id="ok" type="button" value="OK" onclick="OK()"/>
<input id="cancel" type="button" value="Cancel" onclick="shut()"/>
<input id="password" type="password"/>
</div>
</form>

</div>

</body>
</html>

I have tested this in...

I.E. 6.02
Firefox 1.0 :cool:
Mozilla 1.7
Opera 7.54
Netscape 7.1

CBrown
11-23-2004, 05:08 PM
awesome!

i'm sort of new to javascript though, what does the <base> tag do? i've never seen it.

coothead
11-23-2004, 05:23 PM
Hi there CBrown,

Glad that you liked it :D

I use the base tag, basically, to keep the code tidy in the body.
It saves me having to put the full url of the images each time.
In this example there happens to be only one...
background:url('prompt.jpg') no-repeat;
...but of couse there could have been many :supereek:

I forgot to say that the href, in the base tag, is one of my sites :D

CBrown
11-23-2004, 05:30 PM
wow... weird that i've never encountered that.

seems nifty though.

good job again the script.