Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing style element on select

Status
Not open for further replies.

murphyhg

Technical User
Joined
Mar 1, 2006
Messages
98
Location
US
I have 2 radio buttons one of them with the id called pilotverify. If I select the radio button I would like for and event to be triggered called checkForm which will set the ID closeThis display:inline; to display:none;

I am not sure of how to set this up with the code that I have. Can someone please help. Here is the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#closeThis {
display:inline;
}
-->
</style>
<script language="JavaScript" type="text/javascript">
function checkForm() {
pilotverify = document.getElementById("pilotverify").value;
if (pilotverify == 0) {
document.getElementById("closeThis").style.display = "none";
return false;
}
return true;
function showContent() {
document.getElementById("closeThis").style.display = "inline";
}
</script>
</head>

<body>
<form action="" method="post">
<table>
<tr>
<td style="width:50%; border-right:#000000 solid 1px; line-height20px; text-align:right; padding-right:5px;"><span style="color:##3FF0000 !important; font: .900em/20px italic Verdana; margin-right:5px;">(required *)</span><span style="font: .900em/20px normal Verdana, Arial, Helvetica, sans-serif;">Are you an ALPA Member:</span></td>
<td style="padding-left:5px;"><input name="pilotverify" type="radio" value="1" checked="checked" />
<span style="font: .900em/20px normal Verdana, Arial, Helvetica, sans-serif;">Yes</span>
<input onblur="checkForm();" name="pilotverify" type="radio" id="pilotverify" value="0" />
<span style="font: .900em/20px normal Verdana, Arial, Helvetica, sans-serif;">No</span></td>
</tr>
<tr>
<td style="width:50%; border-right:#000000 solid 1px; line-height20px; text-align:right; padding-right:5px;" colspan="2"><label>submit</label>
<input type="submit" name="textfield" />
</td>
<td style="padding-left:5px;">&nbsp;</td>
</tr>
<tr id="closeThis">
<td colspan="2">This is a test</td>
</tr>
</table>
</form>
</body>
</html>
 
make your function:

Code:
function checkForm(strId, show) {
    document.getElementById(strId).style.display = (show) ? 'inline' : 'none';
}

and call it like this:

Code:
<input onchange="checkForm('closeThis', !this.checked);" name="pilotverify" type="radio" id="pilotverify" value="0" />

(you could also call it on the onblur event.)



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
How can I get an immediate response when I select this radio button? Right now, I have to click somewhere else to trigger it.
 
oh ok...

try something like this:

Code:
<input onclick="checkForm('closeThis',[red]true[/red]);" name="pilotverify" type="radio" value="1" checked="checked" />
<span style="...">Yes</span>
<input onclick="checkForm('closeThis',[red]false[/red]);" name="pilotverify" type="radio" id="pilotverify" value="0" />
<span style="...">No</span>



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top