showing a textbox if criteria is met

C

chris

i have a set od radio buttons what i wanty to do is when one particular
button is selected bring up an additional text box for additional
information

how would i do this
 
W

Will Gittoes

chris said:
i have a set od radio buttons what i wanty to do is when one particular
button is selected bring up an additional text box for additional
information

how would i do this

<html>
<head>
<script>
function ShowTextBox(){

Text_b_1 = document.getElementById("TextBoxOne");
Text_b_1.style.display="block"

}
</script>
</head>
<body>

<form name="form1">
<input type="button" onClick="ShowTextBox()">
<input type="text" name="textbox1" value="" id="TextBox1"
style="display:none">
</form>


</body>
</html>


Modify as you need. Just call the ShowTextBox to make the textbox (with
name textbox1 and id TextBox1) appear.

Make Text_b_1.style.display="none" to make it disappear again.
 
M

Michael Winter

[snip]

Valid HTML requires the type attribute.

function ShowTextBox(){

Text_b_1 = document.getElementById("TextBoxOne");

You should declare that variable using the var keyword to prevent it from
becoming global. It's also preferable to access form controls through the
containing form (if it exists) as that is likely to work across more
browsers.

var elem = document.forms['formName'].elements['controlName'];
Text_b_1.style.display="block"

The style element should be tested before it's used to prevent unnecessary
errors. Furthermore, INPUT is an inline-, not block-level, element.

if(elem.style) {
elem.style.display = 'inline';
}

However, as the control should be visible by default (see below), simply
assigning an empty string ('') will be sufficient.

[snip]
<input type="text" name="textbox1" value="" id="TextBox1"
style="display:none">

As Martin said in his post, that is a bad idea. If scripting is not
available, or the browser doesn't support the manipulation of inline
styles, the page becomes unusable. The textbox should only be hidden by a
script, as only a script can show it again.

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top