This is a script I wrote at work. It’s just some javascript that loops through a series of radio buttons for a selection of questions. I’m checking to see if they are checked and if the ones selected are “generally not” or “no”. If so I set the focus to the textarea and prompt the user for input.
| Question | Yes | For the Most Part | Generally Not | No | Don’t Know Other N/A |
||
|---|---|---|---|---|---|---|---|
| 54. | My physical work environment is: | ||||||
| Kept clean by janitorial staff. | |||||||
| Kept in good repair. | |||||||
| Free from safety hazards. | |||||||
| Physically comfortable. | |||||||
| Free from distractions. | |||||||
| If you answered “Generally Not” or “No” for any segment of question ##54 please provide specific examples, including building address, floor, room numbers etc. and a description of the issue. | |||||||
function check54and56(q)
{
// Determine which question was passed to function. 54 or 56?
if(q == ‘54′)
{
questions = ["answer_1", "answer_2", "answer_3", "answer_4", "answer_5"];
ta_answer = “answer_6″;
}
else if(q == ‘56′)
{
questions = ["answer_8", "answer_9", "answer_10"];
ta_answer = “answer_11″;
}
outer: for(i=0; i<questions.length; i++)
{
var radios = document.frm12.elements[questions[i]];
inner: for (var x=0; x <radios.length; x++)
{
// Debug Only
//alert(”Answer ‘” + questions[i] + “‘\nRadio ‘” +x+ “‘ checked: ” + radios[x].checked + “\nRadio ‘” +x+ “‘ value: ” + radios[x].value);
if(radios[x].checked == true)
{
if(radios[x].value == ‘no’ || radios[x].value == ‘generally not’)
{
alert(”Please enter some examples for question “+q+” in the textarea below.”);
document.frm12.elements[ta_answer].focus();
break outer;
}
}
}
}
}
RSS feed for comments on this post · TrackBack URI
Leave a reply
You must be logged in to post a comment.