New to javascript, just want to take a value from a form and save it or print it on t

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.

See you :cool:

I did something similar, but the output is to a textbox.

[HIGHLIGHT=“”]
<!doctype HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>

<head>
<meta name=“GENERATOR” content=“Microsoft FrontPage 5.0”>
<meta name=“ProgId” content=“FrontPage.Editor.Document”>
<title>Radio Buttons</title>
<script type=“text/javascript”>
<!–
function assign_value()
{ var i;
var anxIndex=null, anxietyprint;
for(i=0; i<dfa.anx.length; i++)
{ if(dfa.anx[i].checked==true){ anxIndex=document.anxiety.anx[i].value; }
}
//
switch(anxIndex){
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 substance use or abuse”; break;
default: anxietyprint=“No entry was selected”;
}
//
document.anxiety.T1.value=anxietyprint;
}
// --------
var dfa; // global shortcut to form
window.onload=function(){ dfa=document.getElementById(“myForm”); }
//–>
</script>
<style type=“text/css”>
<!–
body, form, input { font-family:arial, helvetica, sans-serif; color:#000; font-size:13px; font-weight:bold; }
input { color:#000080; font-size:14px; }
p { margin-top:0px; Margin-bottom:3px; }
–>
</style>
</head>

<body>

<form id=“myForm” name=“anxiety” method=“get” action>
<p>Level of anxiety noted:</p>
<p><input type=“radio” name=“anx” value=“no”>NONE</p>
<p><input type=“radio” name=“anx” value=“mild”>MILD</p>
<p><input type=“radio” name=“anx” value=“moderate”>MODERATE</p>
<p><input type=“radio” name=“anx” value=“high”>HIGH</p>
<p><input type=“radio” name=“anx” value=“affected”>AFFECTED BY SUBSTANCE USE</p>
<p><br>
<input type=“text” name=“T1” value size=“70”></p>
</form>
<p><button type=“button” onClick=“assign_value()”>Assign Anxiety</button></p>

</body>

</html>

Thank you Pablogo and AllanP. What you whipped out in 2 minutes I have been fighting with all day. Kindest Regards…