Welcome to WebmasterWorld Guest from 54.159.246.164

Forum Moderators: open

Message Too Old, No Replies

show/hide input based on radio btn selected

show/hide input based on radio btn selected

   
5:01 am on Feb 10, 2011 (gmt 0)

5+ Year Member



I am asking for a bit of help in javascript. I am trying to show the text field when private is selected. But, if the user elects the pblic radio again I want the text field to disappear.

in the head:

<script type="text/javascript">
function onSelect(objSelect){
if (objSelect.value=="1") {
document.getElementById("otherOpt").style.display='block'; // Show Options
}
}
</script>


Then the following in the form:

<b>Website Authorization:</b> <br><input type="radio" name="name" value="0" checked /> Public&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<input type="radio" name="name" value="1" onfocus="onSelect(this)"/> Private<div id="otherOpt" style="display:none"> <br>Website Password: <input type="text" name="name2" size="25" maxlength="29"/></div>
10:49 am on Feb 10, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



function onChange(obj,show){
var el = document.getElementById("otherOpt");
if (obj.checked==show) { el.style.display=''; } // Show Options
else { el.style.display='none'; }
}

on public
onchange="onChange(this,true)"
on private
onchange="onChange(this,false)"

or replace two radios with single checkbox ?
1:08 am on Feb 11, 2011 (gmt 0)

5+ Year Member



thanks davevk...got it to work the way i wanted.
5:57 am on Feb 14, 2011 (gmt 0)

5+ Year Member



I got it to work at time of order but not at time of edit....any suggestions? I would like to show the password only if private is checked.

in the head
<script type="text/javascript">
function onChange(obj,show){
var el = document.getElementById("otherOpt");
if (obj.checked==show) { el.style.display=''; } // Show Options
else { el.style.display='none'; }
}
</script>


in the body
<b>Website Authorization:</b> <br><input type="radio" name="accessprotect" value="0" <?php if($radioaccess=='0') {echo("checked");} ?> onchange="onChange(this,false)"/> Public&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<input type="radio" name="accessprotect" value="1" onchange="onChange(this,true)" <?php if($radioaccess=='1') {echo("checked");} ?>/> Private<div><br>Private Website Access Code: <input type="password" name="accesspword" size="25" maxlength="29" value="<?php echo( $accessword ) ;?>" />&nbsp;&nbsp;Please use a different code than your account password.</div>
2:02 pm on Feb 14, 2011 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Your div is missing the "otherOpt" id.

Try this:

<div id="otherOpt" <?php if($radioaccess=='0') {echo("style='display:none;'");} ?>
><br>Private Website Access Code: <input type="password" name="accesspword" size="25" maxlength="29" value="<?php echo( $accessword ) ;?>" />&nbsp;&nbsp;Please use a different code than your account password.</div>
1:45 am on Feb 15, 2011 (gmt 0)

5+ Year Member



thanks fontiman