...

View Full Version : HELP concerning javascript input values



DooM_MonkeY
05-27-2004, 11:46 PM
First, id like 2 say hello because i am new here and dont think im dumb, because im 13 years old and know Css, Html, and learning Javascript...

Ok, now 2 my question. Is there any way to have the default value of a text box be in text, but then when u focus on it, it will change to the dots for a password? look at my code so far:

http://www.freewebs.com/death_by_monkeys/glow%20test.htm

o and the music on there isnt mine but im not going to use it for anything, just to see how the code worked with music. All the other codes on that page are just some codes ive been working on

DooM_MonkeY
05-28-2004, 12:09 AM
o and i already tryed

function type_change() {

document.all.box2.type="password";
}

but it didnt work so any suggestions??

Basscyst
05-28-2004, 12:50 AM
hmm. . .

you might try:



<html>
<head>
<script type="text/javascript">

function changeInput()
{
document.getElementById('passSpot').innerHTML='<input type="password" id="pass">';
document.getElementById('pass').focus();
}
</script>
</head>
<body>
<form>
<div id='passSpot'>
<input type="text" value="Enter Password" onfocus="changeInput()">
</div>
</form>
</body>
</html>


Doesn't seem to want to focus on the password field after the switch, not sure why.

Basscyst

DooM_MonkeY
05-28-2004, 12:57 AM
omg it worked!! wow, it was that easy, i never thought of an innerHTML for that. thank you, ive been needing 2 crack the math on that for a while, lemme see how it works with my other scripts

hmmmm, wonder y it isnt focusing

DooM_MonkeY
05-28-2004, 01:07 AM
wait, how would i put the onmouseover="" type stuff in that? in innerHTML the javascripts never work for me. Is it because the ' tags can't be used inside each other? how would i change the ' tags so the scripts inside of the innerHTML still work?

(like i might have said, still new to Javascript)

Basscyst
05-28-2004, 02:30 AM
I think you are wondering how you would pass a variable to the function:

Seperate the string (the html) from a variable with the plus sign. Make sure you close the string with a quote. You can use either or but not both. If you start a string with a single quote you must close the string with a single quote. Allowing you to use the double quote for the HTML.

somthing like:



<html>
<head>
<script type="text/javascript">
var str='mommy';
function doAlert(x)
{
alert(x);
}

function changeInput()
{
document.getElementById('passSpot').innerHTML='<input type="password" id="pass"><input type="button" onclick=doAlert("'+str+'")>';
document.getElementById('pass').focus();
}
</script>
</head>
<body>
<form>
<div id='passSpot'>
<input type="text" value="Enter Password" onfocus="changeInput()">
</div>
</form>
</body>
</html>

DooM_MonkeY
05-28-2004, 02:41 AM
yes thank you, i still havent figured out the focus problem yet but im working on it with this: http://www.freewebs.com/death_by_monkeys/password_testing.htm

you have to click the reset button (fake reset button) twice until the 'password' value comes back tho

with the colors i was just trying to see if a style could be applied to it (dont no y it wouldnt but hey)

Willy Duitt
05-28-2004, 09:20 PM
Try this:

<script type="text/javascript">
<!--//
function changeType(input){
if(input.type == 'text'){
password = document.createElement('input');
password.name = 'password'
password.type = 'password';
input.parentNode.insertBefore(password,input);
input.parentNode.removeChild(input);
password.value = '';
password.focus();
}
}
//-->
</script>
</head>

<body>
<form method="get" action="">
Password:<input type="text" value="Please Enter a Password"
name="password" onfocus="changeType(this)">
</form>

Willy Duitt
05-28-2004, 09:32 PM
BTW: Below is an example of adding an event handler to call a javascript function. (I changed the alert to innerHTML because the alert would kill the focus demonstration)


<script type="text/javascript">
<!--//
var str='mommy';
function doAlert(x){
document.getElementById('test').innerHTML = x;
}


function changeType(input){
if(input.type == 'text'){
password = document.createElement('input');
password.name = 'password'
password.type = 'password';
password['onclick'] = new Function(doAlert(str));
input.parentNode.insertBefore(password,input);
input.parentNode.removeChild(input);
password.value = '';
password.focus();
}
}
//-->
</script>
</head>

<body>
<form method="get" action="">
Password:<input type="text" value="Please Enter a Password"
name="password" onfocus="changeType(this)">
</form>
<span id="test"></span>

DooM_MonkeY
05-29-2004, 01:26 AM
hehey that workd too, thanks alot guys uve really helped :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum