views:

31

answers:

1

I would like to make this form dynamic with prototype. I mean, the radio should be disabled, but when you chose one, with js, it should turn them enabled, same way if you chose the other one, the 1st should turn disabled.

This is my HTML, but I have no idea where to start with JS to make this work, thank you

<form id="uploadForm" method="post" action="/parser/parseCurriculumVitae.do" enctype="multipart/form-data">
<fieldset>
        <div id="uploadCv">
                <input type="radio" id="uploadCvSelector" name="uploadFormSelector"/>
                <input disabled type="file" id="uploadCv" name="uploadCv" />
        </div>
        <div id="pastedCv">
                <input type="radio" id="pastedCvSelector" name="uploadFormSelector" />
                <textarea disabled id="pastedCv" name="pastedCv" rows="8" cols="40" onclick="this.value=''">Paste your Cv Here</textarea>
        </div>
<input type="submit" value="Send'em!"/>
</fieldset>
</form>
+1  A: 

i think your request to use prototype prejudices the answer. you can do this just fine without a library.

<input type="radio" id="pastedCvSelector" name="uploadFormSelector" onclick="document.getElementById('pastedCv').disabled=false;document.getElementById('uploadCv').disabled=true;">
<textarea disabled id="pastedCv" name="pastedCv" rows="8" cols="40" onclick="this.value=''">Paste your Cv Here</textarea>

UPDATED (again)

SpliFF
I think you meant "document.getElementById('pastedCvSelector').checked=true"
PortableWorld
The textarea should remain disabled until you select the parent Radio.
BoDiE2003
You are right, My bad, there is the right logic.if radio id uploadCvSelector is checked, input file id uploadCvSame for the second radio case with pastedCvSelector and pastedCv textarea
BoDiE2003
you've confused me now. "disabled" has a special meaning in regards to inputs. do you really want the textarea "disabled", or hidden or what?
SpliFF
I want them to be like in the html, "disabled" until you select the parent radio. But if you switch to another radio, the parent textarea or inputFile, depeding of the case, should switch back to disabled.
BoDiE2003
ok, i assumed you wanted the radios checked if you clicked in the text/file inputs. what you actually want is the text/file fields disabled attribute toggeled when you click the radios. I've update the code. (if you want both try combining my original answer with the new one).
SpliFF
I did, now works perfectly. Thank you, I apretiate it.
BoDiE2003