PDA

View Full Version : JavaScript Help =]



MrCraig
18-12-2007, 07:15 PM
Ok,

Im learning more javascript and so far, I can do most things, but only to do them in the onclick attribute using 'this'

Say i wanted a button that would enable fields in a form using a function, how would i do this?

For example


<head>
<script type="text/javascript">
function enable()
{
document.form1.field1.disabled = 'false';
document.form1.field2.disabled = 'false';
}
</script>
</head>
<body>
<form name="form1">
<input type="text" disabled="disabled" name="field1" />
<input type="text" disabled="disabled" name="field2" />
<input type="button" onclick="enable()" />
</form>
</body>


Thanks for any help :)

lolwut
18-12-2007, 07:48 PM
Little bit of fiddling:
(You where along the right lines generally)


<html>
<head>
<script type="text/javascript">
function enable()
{
document.form1.field1.disabled = false;
document.form1.field2.disabled = false;
}
</script>
</head>
<body>
<form name="form1">
<input type="text" disabled="disabled" name="field1" />
<br />
<input type="text" disabled="disabled" name="field2" />
<br />
<input type="button" onclick="enable()" value="Enable" />
</form>
</body>
</html>

MrCraig
18-12-2007, 07:50 PM
lol, i just coded form as example, (thats why i didnt put the line breaks in :P)

But thanks for help :)

Il try that now :D

Florx
18-12-2007, 07:56 PM
Just a little extension for if you wanted to enable and disable using one button you could do this



<html>
<head>
<script type="text/javascript">
function enable()
{
d = document.form1.field1.disabled;

if(d == false){

document.form1.field1.disabled = true;
document.form1.field2.disabled = true;

}else{

document.form1.field1.disabled = false;
document.form1.field2.disabled = false;

}


}
</script>
</head>
<body>
<form name="form1">
<input type="text" disabled="disabled" name="field1" />
<br />
<input type="text" disabled="disabled" name="field2" />
<br />
<input type="button" onclick="enable()" value="Enable" />
</form>
</body>
</html>

MrCraig
18-12-2007, 08:05 PM
Oooh

Ty Jake :)
+REP to both - Have to spread :|

-Really ought to learn javascript lol

Want to hide these adverts? Register an account for free!