homepage Welcome to WebmasterWorld Guest from 54.166.159.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
show/hide input based on radio btn selected
show/hide input based on radio btn selected
weddingm

5+ Year Member



 
Msg#: 4264971 posted 5:01 am on Feb 10, 2011 (gmt 0)

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>

 

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4264971 posted 10:49 am on Feb 10, 2011 (gmt 0)

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 ?

weddingm

5+ Year Member



 
Msg#: 4264971 posted 1:08 am on Feb 11, 2011 (gmt 0)

thanks davevk...got it to work the way i wanted.

weddingm

5+ Year Member



 
Msg#: 4264971 posted 5:57 am on Feb 14, 2011 (gmt 0)

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>
Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4264971 posted 2:02 pm on Feb 14, 2011 (gmt 0)

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>

weddingm

5+ Year Member



 
Msg#: 4264971 posted 1:45 am on Feb 15, 2011 (gmt 0)

thanks fontiman

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved