PDA

View Full Version : Using Javascript to disable input boxes buttons etc...


HSV Guy
11-09-2002, 08:40 AM
If you have a look at http://homepage.powerup.com.au/~bfarquha/ so you know what I am talking about.

Ok what I want to do is use a javascript so that one half of input boxes and buttons will be disable while the other half are enabled. The way I was thinking of implementing it was to add an extra 2 buttons (or even 1 and make it so that its name changes). By default the existing user buttons would be enabled but if a new user wanted to create a new account they could click a button which would enable the new user buttons.

I would also be able to use this in a few other places.

P.S. You can't login or anything as I've only uploaded that 1 page. Also if you have a look at my page can you please tell me what size the text is. I've added a pic down the bottom showing how it should be on one side and on the other it shows how it displys when I am using my user account on my other computer.

So far it has only been stuffed up, on my other computer while I was accessing it from my account in IE (Windows XP). In someone else's account it was fine and it is only fine if I view it from my account in Opera (although the text is black) so I don't know why it's stuffed up in IE (and I've tried a Ctrl+F5).

The Quinn
11-09-2002, 09:27 AM
To have the new user buttons disabled, just add 'disabled' to the form tag.
ie change
<form action = "password.php" method = "post" form name = "submit2">to
<form action = "password.php" method = "post" form name = "submit2" disabled>
To enable the form use 'document.submit2.disabled=false'
eg using a button
<input type="button" value="I'm New" onClick="document.submit2.disabled=false">

Your text looked fine to me, I use IE6

HSV Guy
11-09-2002, 11:09 PM
Thanks for that Quinn, but although that makes them appear disabled you can still click on them. If you have a look at the page again I've added a few buttons so you can disable each field. But as you can see you can still type in data and click the button, but I want to make it so that you can't click the button.

The Quinn
11-10-2002, 08:59 AM
I thought disabling the form would actually disable all of the fields properly, but it appears to only cause them to display as if they are disabled.
If you want the fields disabled properly, it seems that you have to do each one separately.
So to disable the second form you would use
document.submit2.STUDENTNUMBER.disabled=true
document.submit2.PASSWORD1.disabled=true
document.submit2.PASSWORD2.disabled=true
document.submit2.Create.disabled=true
If you just want to disable the button though, you only need
document.submit2.Create.disabled=true
One other thing, as far as I know you don't need to close an input tag by ending it with a '/>'.

giz
11-10-2002, 09:44 AM
The tag ending /> is only required if you are writing fully validated XML or XHTML pages. For HTML pages you must not use this ending as it confuses some browsers. Just the > is required.

Jon Hanlon
11-10-2002, 05:30 PM
The attribute you want to set is disabled.
The trouble is that most browsers get confused if you say disabled='false', so you have to do it via script.

Anyway, your site has bigger problems. It gets into a loop regarding the username length. It's generally better to use onchange rather than onclick to avoid this issue.

At the end of the day though I wouldn't bother. The user can only hit one submit button so what does it matter? And what happens if the user starts to fill in the wrong side of the screen - how do they reset? By disabling half the screen you're making things harder on the end-user, not easier.