Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > showing a textbox if criteria is met

Reply
Thread Tools

showing a textbox if criteria is met

 
 
chris
Guest
Posts: n/a
 
      08-21-2004
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



 
Reply With Quote
 
 
 
 
Will Gittoes
Guest
Posts: n/a
 
      08-21-2004
chris wrote:
> 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.
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      08-21-2004
On Sat, 21 Aug 2004 23:25:47 +1200, Will Gittoes <(E-Mail Removed)>
wrote:

[snip]

> <script>


Valid HTML requires the type attribute.

<script type="text/javascript">

> 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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid ButtonColumn only visible when criteria met? John Mason ASP .Net 2 05-02-2005 04:53 PM
showing a textbox if criteria is met chris Javascript 3 08-21-2004 03:42 PM
Not able to popup the calendar due to PostBack untill al the validations have been met DotNetJunkies User ASP .Net 1 05-01-2004 07:14 AM
Sending an email after a condition is met in SQL server Simon Harvey ASP .Net 2 02-27-2004 02:09 PM
Met employees today Brat MCSE 35 01-29-2004 05:34 PM



Advertisments