Just want to take information a user selects in a form and either save it of print it on the client side. any help would be greatly appreciated. This is what I have pieced together so far…
<html>
<head>
<Script language= "Javascript">
<!--
var anxiety= new Array()
anxiety[0]="No";
anxiety[1]="mild";
anxiety[2]="Moderate";
anxiety[3]="High";
anxiety[4]="affected by substance use or abuse";
//-->
var anxietyprint="not assessed";
function set_anxiety()
{
}
</script>
<script language=text/javascript">
function assign_value()
{
if (anxiety.value=="no")
{
anxietyprint='Client presented with no anxiety';
}
else
if (anxiety.value=="mild")
{
anxietyprint='Client presented with mild anxiety';
}
else
if (anxiety.value=='moderate')
{
anxietyprint="Client presented with moderate anxiety";
}
else
if (anxiety.value=='high')
{
anxietyprint="Client presented with high anxiety";
}
else
if (anxiety.value=='affected')
{
anxietyprint="Client presented with anxiety affected by substance use or abuse";
}
{
document.write(anxietyprint);
}
}
</script>
<P>
</head>
<body>
<FORM name="anxiety">
Level of anxiety noted:<br>
<input type="radio" name="anx" value="no" /> NO<br />
<input type="radio" name="anx" value="mild" />MILD<br />
<input type="radio" name="anx" value="moderate" />MODERATE<br />
<input type="radio" name="anx" value="high" />HIGH<br />
<input type="radio" name="anx" value="affected" />AFFECTED BY SUBSTANCE USE<br />
</form>
<button type="button" onClick="assign_value()">Assign Anxiety</button>
</body>
Well, if i understand the basis of what are you trying to do, the code should be something like that
<html>
<head>
<Script language= "Javascript">
var anxiety= new Array()
anxiety[0]="No";
anxiety[1]="mild";
anxiety[2]="Moderate";
anxiety[3]="High";
anxiety[4]="affected by substance use or abuse";
var anxietyprint="not assessed";
function set_anxiety()
{
//use?
}
function assign_value()
{
var anxCol = document.getElementsByName("anx");
var i = 0;
var o = null;
for (i=0;i<(anxCol.length-1);i++){
//looking for the radio button checked
var o = anxCol[i];
if (o.checked){
//ok, here it is
break;
}
o = null;
}
if (o == null){
//so, none checked ?
window.alert ("no one selected");
}else{
switch(o.value){
case ("no"):
anxietyprint='Client presented with no anxiety';
break;
case ("mild"):
anxietyprint='Client presented with mild anxiety';
break;
case ("moderate"):
anxietyprint="Client presented with moderate anxiety";
break;
case ("high"):
anxietyprint="Client presented with high anxiety";
break;
case ("affected"):
anxietyprint="Client presented with anxiety affected by aubstance use or abuse";
break;
default:
//something else
anxietyprint=" something else?";
break;
}
document.write(anxietyprint);
}
}
</script>
<P>
</head>
<body>
<FORM name="anxiety">
Level of anxiety noted:<br>
<input type="radio" name="anx" value="no" /> NO<br />
<input type="radio" name="anx" value="mild" />MILD<br />
<input type="radio" name="anx" value="moderate" />MODERATE<br />
<input type="radio" name="anx" value="high" />HIGH<br />
<input type="radio" name="anx" value="affected" />AFFECTED BY SUBSTANCE USE<br />
</form>
<input type="button" onclick="assign_value()" value="Assign Anxiety">
</body>
</html>
Note the “input” tag instead of the “button” tag and the “value” of it.
Things i do not get understood are the use of the array “anxiety” and the function “set_anxiety()” guess you are still codding the page.