/*helo every one, I am just a newbie in javascript, but can any one help me with the second function?*/
<html>
<head><title>survey2</title>
<script type="text/javascript">

var Item = new Array();

Item[100] = 15;
Item[101] = 10;
Item[102] = 5;
Item[103] = 0;

function show_it()
{
    var total = 0;
    var Details = " ";
    var formElement;
    
    formElement = document.form1.choose
    if (formElement[0].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[2].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[2].value]);
    }
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

    formElement = document.form1.choose2
    if (formElement[0].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[2].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[2].value]);
    }

	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

    formElement = document.form1.choose3
    if (formElement[0].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[2].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[2].value]);
    }

	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

    formElement = document.form1.choose4
    if (formElement[0].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[2].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[2].value]);
    }

	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

    formElement = document.form1.choose5
    if (formElement[0].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[2].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[2].value]);
    }
	
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

 formElement = document.form1.choose6
    if (formElement[0].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
        
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[1].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[2].value]);
    }
	
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

 formElement = document.form1.choose7
    if (formElement[0].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
      
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[1].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[2].value]);
    }
	
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

 formElement = document.form1.choose8
    if (formElement[0].checked == true)
    {
      
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[1].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[2].value]);
    }
	
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

 formElement = document.form1.choose9
    if (formElement[0].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[1].checked == true)
    {
        
        total = total + parseFloat(Item[formElement[2].value]);
    }
	
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

 formElement = document.form1.choose10
    if (formElement[0].checked == true)
    {
       
        total = total + parseFloat(Item[formElement[0].value]);
    }
    else if (formElement[1].checked == true)
    {    
       
        total = total + parseFloat(Item[formElement[1].value]);
    }
    else if (formElement[1].checked == true)
    {
      
        total = total + parseFloat(Item[formElement[2].value]);
    }
	
	else{
	
	total = total + parseFloat(Item[formElement[3].value]);
	}

	 Details = Details + "\nTotal Points: " + total;
	document.form1.textDetails.value=Details;

/*how can I, make this function work?
}
function conditions(){	
if(total<=150 && total>100){   
    
	Details = Details + "\n\nTotal Points: " + total + "excellent";
	document.form1.txtDetails.value = Details;	

}
else if(total<=100 && total>25){
    Details = Details + "\n\nTotal Points: " + total+"good";
    document.form1.txtDetails.value = Details;
	
}
else if(total<=25)
    Details = Details + "\n\nTotal Points: " + total+"magshift ka na!!";
    document.form1.txtDetails.value = Details;
} */
}   
</script>
</head>
<body>
<font face="Arial">

<form name="form1">

<center>
<table bgcolor="CCCCCC" float:"left" cellpadding="2">

<ol>

<th bgcolor="white" colspan="5"> Are you made for IT field?</th>

<tr align="center">

<td></td>
<td width="25">Strongly Agree</td>
<td width="25">Agree</td>
<td width="25">Somewhat Agree/Disagree</td>
<td width="25">Disagree</td>

</tr>

<tr >
<td><li>When presented with a problem, many different solutions occur to me without much effort.</li></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose" value="103"/></td>
</tr>

<tr>
<td><li> Noticing minor details is one of my strengths.</li></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose2" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose2" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose2" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose2" value="103"/></td>
</tr>

<tr>
<td><li> As a general rule, I am on the lookout for different ways to approach a problem.</li></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose3" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose3" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose3" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose3" value="103"/></td>
</tr>

<tr>
<td><li>  I often find myself trying to remember what I was about to do next.</li></td> 
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose4" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose4" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose4" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose4" value="103"/></td>
</tr>

<tr>
<td><li>  It irritates me when others in my group perform better than I do. </li></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose5" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose5" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose5" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose5" value="103"/></td>
</tr>

<tr>
<td><li> I find it difficult to decide which things are most important when I have a lot of tasks to do. </li></td>  
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose6" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose6" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose6" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose6" value="103"/></td>
</tr>

<tr>
<td><li>  I often find myself falling behind in things that need to be done.</li></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose7" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose7" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose7" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose7" value="103"/></td>
</tr>

<tr>
<td><li>  I hate changing environments (moving, changing job/school, traveling).</li></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose8" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose8" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose8" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose8" value="103"/></td>
</tr>

<tr>
<td><li>   I am easily discouraged.</li></td>  
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose9" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose9" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose9" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose9" value="103"/></td>
</tr>

<tr>
<td><li>I pay careful attention to small things when I'm completing a task.</li> </td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose10" value="100"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose10" value="101"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose10" value="102"/></td>
<td style="cursor:hand;cursor:pointer" align="center"><input type="radio" name="choose10" value="103"/></td>
</tr>            
</font>
</ol> 
<table>
<tr align="center" valign="bottom">

<td style="cursor:hand;cursor:pointer"><input type="button" value="Update" Name=butupdate onclick="show_it()"></td>

<td style="cursor:hand;cursor:pointer"><input type="reset" value="Erase form"></td>

<textarea rows=20 cols=35 id=textDetails name=txtDetails></textarea>

</td>
</tr>
</table>
</table>

</form> 
</center>

</body>
</html>

Kelvin,

Both JS and HTML can be be simplified considerably by looping, firstly to build the questions table, then to scan it when the "Update" button is pressed.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>survey2</title>
<style>
body, td { font-family:arial; }
#questions_table {  }
#questions_table th, #questions_table td { background-color:#cccccc; font-size:10pt; }
td.radio { text-align:center; }
#details { width:250px; padding:12px; border:1px solid #999; text-align:center; }
</style>

<script type="text/javascript">
var questions = [
    "When presented with a problem, many different solutions occur to me without much effort.",
    "Noticing minor details is one of my strengths.",
    "As a general rule, I am on the lookout for different ways to approach a problem.",
    "I often find myself trying to remember what I was about to do next.",
    "It irritates me when others in my group perform better than I do.",
    "I find it difficult to decide which things are most important when I have a lot of tasks to do.",
    "I often find myself falling behind in things that need to be done.",
    "I hate changing environments (moving, changing job/school, traveling).",
    "I am easily discouraged.",
    "I pay careful attention to small things when I'm completing a task."
];

function show_it(){
  var total = 0;
  var formElement;
  for(var i=0; i<questions.length; i++){
    formElement = document.form1['choose'+i];
    checkedValue = -1;
    for(var j=0; j<4; j++){
      if(formElement[j].checked) {
        checkedValue = formElement[j].value;
        break;
      }
    }
    if(checkedValue == -1){
      alert('You have not answered question ' + (i+1));
      return;
    }
    else{
      total += parseFloat(checkedValue);
    }
  }
  message = (total>100) ? "Excellent" : (total<=100 && total>25) ? "Good" : "Magshift ka na!!";
  var details = document.getElementById('details');
  details.innerHTML = "Total Points: " + total + "<br><br>" + message;
}
function clearResults(){
  details.innerHTML = "";
}

onload = function(){
  var t = document.getElementById('questions');
  var values = ['15', '10', '5', '0'];
  var tr, td;
  for(var i=0; i<questions.length; i++){
    var tr = t.insertRow();
    var td = tr.insertCell();
    td.innerHTML = questions[i];
    var input;
    for(var j=0; j<4; j++){
      td = tr.insertCell();
      td.className = 'radio';
      td.innerHTML = '<input type="radio" name="choose' + i + '" value="' + values[j] + '"/>';
    }
  }
}
</script>
</head>

<body>
<form name="form1">

<table id="questions_table">
<tr>
<th bgcolor="white" colspan="5">Are you made for IT field?</th>
</tr>
<tr align="center">
<td></td>
<td width="25">Strongly Agree</td>
<td width="25">Agree</td>
<td width="25">Somewhat Agree/Disagree</td>
<td width="25">Disagree</td>
</tr>
<tbody id="questions"></tbody>
</table>

<table>
<tr align="center" valign="bottom">
<td><input type="button" value="Update" name="butupdate" onclick="show_it()"></td>
<td><input type="reset" value="Erase form" onclick="clearResults()"></td>
<div id="details">&nbsp;</div>
</td>
</tr>
</table>

</form> 
</center>

</body>
</html>

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.