Click to See Complete Forum and Search --> : Textbox disabled until radio enables it?


Jick
09-05-2003, 07:15 PM
I have this form with three radio buttons and one textbox. I wanted to know if it was possible to have it so the textbox is disabled until you select the right radio button and then it becomes enabled and if you select another radio button it will re-disable the textbox. So basicly what it is doing is making it so the user cannot type in the textbox unless they choose the right radio button. I wanted to do this with PHP and not JavaScript if possible so it will work with all users. Is this possible? I would greatly appreciate it. :D

PunkSktBrdr01
09-05-2003, 07:29 PM
To do that in PHP, you'd have to submit the form. The PHP doesn't appear in the browser, so it can't dynamically control page attributes. Try inserting this into the radio button:


onChange="enableText();"


and put this in the page head:


<script language="JavaScript" type="text/javascript">
function enableText() {
var radio_text = document.form_name.getElementById(radio_id);
var text_box = document.form_name.getElementById(textbox_id);
if(radio_text.selected = true) {
text_box.disabled = false;
}
else {
text_box.disabled = true;
}
}


Be sure to replace the stuff in italics with the correct info. I haven't actually tested this, so it might not work. You should check in the JavaScript forum if you need more help. Good luck!

Jick
09-05-2003, 08:41 PM
Thank you for replying. Is there any other way to accomplish this? I think it's like 18% of users don't have JavaScript enabled.

PunkSktBrdr01
09-05-2003, 09:33 PM
JavaScript and VBScript are the only client-side languages that I know of that would be able to do this, but they could be disabled. Your best option is probably to just leave the text box enabled and only process it if the radio button is selected. Otherwise, you'd have to reload the page whenever a new radio button is selected. Hope that helps!

pyro
09-05-2003, 09:40 PM
PunkSktBrdr01 is right -- it's more of a JavaScript thing. Also it is 13% (http://www.thecounter.com/stats/2003/May/javas.php) who do not hava JavaScript disabled...

spykemitchell
09-19-2003, 04:23 PM
13% thats a hell of alot!!!!