/    Sign up×
Community /Pin to ProfileBookmark

Show/Hide a div when a radio is/isnt selected

Hello, this is the first time i’ve attempted to use this kind of scripting in a form.
basically, my form contains basic information.

i have 2 radios to suggest the best way to contact someone, radios are phone and email.

When the phone radio is selected i want a <div to appear which contains “best time to contact”

This is my current scripting, please could i have a detailed response as i am having no luck with the current soultions i have found

.
..

<span>Best way to reply:</span>

<input type=”radio” name=”reply” value=”Email” id=”reply_0″ /> E-mail <BR />

<div style=”margin-left:270px;”><input type=”radio” name=”reply” value=”Phone” id=”reply_1″ onclick=””/>Phone</div> <br/>

<div id=”timehide”><span>Best time to get hold of you:</span>
<select>
<option value=”Any”>Any</option>
<option value=”06:00 – 10:00″>06:00 – 10:00</option>
<option value=”10:00 – 12:00″>10:00 – 12:00</option>
<option value=”12:00 – 14:00″>12:00 – 14:00</option>
<option value=”14:00 – 16:00″>14:00 – 16:00</option>
<option value=”16:00 – 18:00″>16:00 – 18:00</option>
<option value=”18:00 – 20:00″>18:00 – 20:00</option>
</select></div>


..
.

Please if any one can solve my issue i will be greatly thankful!!

Cheers, ben!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKEROct 16.2009 — If this is not what you want, it should be close ...

Give it a try:
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Respond&lt;/title&gt;
&lt;script type="text/javascript"&gt;
// From: http://www.webdeveloper.com/forum/showthread.php?t=218396

function ShowTimes(IDS,flag) {
var status = 'none';
if (flag) { status = 'block'; }
document.getElementById('timehide').style.display = status;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;span&gt;Best way to reply:&lt;/span&gt;
&lt;input type="radio" name="reply" value="Email" id="reply_0" onchange="ShowTimes('timehide',false)"/&gt; E-mail &lt;BR /&gt;
&lt;div style="margin-left:270px;"&gt;
&lt;input type="radio" name="reply" value="Phone" id="reply_1" onchange="ShowTimes('timehide',true)"/&gt;Phone
&lt;/div&gt;
&lt;br&gt;
&lt;div id="timehide" style="display:none"&gt;
&lt;span&gt;Best time to get hold of you:&lt;/span&gt;
&lt;select&gt;
&lt;option value="Any"&gt;Any&lt;/option&gt;
&lt;option value="06:00 - 10:00"&gt;06:00 - 10:00&lt;/option&gt;
&lt;option value="10:00 - 12:00"&gt;10:00 - 12:00&lt;/option&gt;
&lt;option value="12:00 - 14:00"&gt;12:00 - 14:00&lt;/option&gt;
&lt;option value="14:00 - 16:00"&gt;14:00 - 16:00&lt;/option&gt;
&lt;option value="16:00 - 18:00"&gt;16:00 - 18:00&lt;/option&gt;
&lt;option value="18:00 - 20:00"&gt;18:00 - 20:00&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

Good Luck!

?
×

Success!

Help @ben_johnson1991 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...