I have this radio button group, and I would like to add an onclick function.
Ultimately, I am aiming for the selection to determine which form is shown, but for now i just need to get the form to react to the mouse clicks.
This is the code:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact THT</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function radio() {
if(document.getElementById("msg_type_0").checked == true) document.write("avl is selected");
else if (document.getElementById("msg_type_1").checked == true) document.write("gen is selected");
else (document.getElementById("msg_type_2").checked == true) document.write("fbk is selected");
</script>
</head>
<body>
<div id="container">
<div id="titlebar">
<div id="logo" style="float:left;">
<img src="images/doncaster.gif" alt="tht logo" />
</div>
<div id="header" style="float:right;">
<h1>Contact THT</h1>
Send a message to the Co-ordinating Team, <br />
or feedback about this site
</div>
<div id="nav">
<?php include("nav.php"); ?>
</div>
</div>
<div id="content">
<h3>I would like to send...</h3>
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input type="radio" name="msg_type" value="avl" id="msg_type_0" onclick="radio()" />
...my availability</label>
<br />
<label>
<input type="radio" name="msg_type" value="gen" id="msg_type_1" onclick="radio()"/>
...a general message</label>
<br />
<label>
<input type="radio" name="msg_type" value="fbk" id="msg_type_2" onclick="radio()"/>
...feedback about the site</label>
<br />
</p>
</form>
so far the code seem ok, except that you had not properly closed the radio function's body and document.write will clear your document content:
Code:
function radio(){
....
} // << missing in your code
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
missed an if after the last else clause. if after an else you want to perform another comparison, you have to include the if statement:
Code:
else if(document.getElementById("msg_type_2").checked == true) alert("fbk is selected");
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
Bookmarks