Welcome to WebmasterWorld Guest from 54.144.7.239

Forum Moderators: open

Message Too Old, No Replies

If Then ?

form syntax

     
8:10 pm on Mar 23, 2012 (gmt 0)

New User

joined:Mar 23, 2012
posts: 2
votes: 0


I'm not sure if this falls under if, then syntax, but I have a radio button and I'd like a set of text fields to open only if Option A is selected. Does anyone know a script for this? -Much obliged.
2:54 am on Mar 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 7, 2010
posts: 119
votes: 0


This is one way, this is my first time using the
disabled
attribute so you may want to investigate further.


<form>
<fieldset>
<label for="ena">Enable</label><input type="radio" id="ena" name="ed" value="Enable"/>
<label for="dis">Disable</label><input type="radio" id="dis" name="ed" value="Disable"/>
</fieldset>
<fieldset>
<input type="text" id="some" name="something">some</input>
<input type="text" id="thing" name="something" disabled="disabled">thing</input>
</fieldset>
</form>


<script type="text/javascript">
function enable(){
document.getElementById("ena").onclick=function(){
document.getElementById("thing").disabled=false;
}
}

function disable(){
document.getElementById("dis").onclick=function(){
document.getElementById("thing").disabled=true;
}
}
window.onload = function(){
enable();
disable();
}
</script>
3:17 am on Mar 24, 2012 (gmt 0)

New User

joined:Mar 23, 2012
posts: 2
votes: 0


Hmmm. I got the radio button and both text fields with either choice. I tried putting the <script> between <head></head> but got same result.
Thanks though.
10:14 am on Mar 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 7, 2010
posts: 119
votes: 0


wrap the entire reply in the body tags and it will work.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members