Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Code for Personality Inventories? 2

Status
Not open for further replies.

flasher40

Technical User
Apr 13, 2007
80
US
Hi,

Of course, there are a lot of Javascript templates available for multiple-choice tests where only one choice per test item is scored as correct.

On the other hand, I'd like to develop a personality/behavioral inventory where the scoring isn't right/wrong. For example:

1. You change jobs very frequently.
o Always
o Often
o Sometimes
o Rarely
o Never

I've used a true/false Javascript format for a simple personality inventory but would like to do something more sophisticated using a Likert scale similar to the sample item above. I'm assuming the code for scoring an inventory like this would be a lot more complex than for simple right/wrong tests.

Does anyone happen to have that code on hand which they would be willing to share, or know where it can be found online?

Thanks,
Bill
 
As I understand it a Likert scale is simply a score of, for example, 1-5.

So create your form with radio buttons and give each a value according to the scale.

Code:
<label for="f1-1">Strongly Disagree <input type="radio" id="f1-1" name="field1" value="1"></label>
<label for="f1-2">Disagree <input type="radio" id="f1-2" name="field1" value="2"></label>
<label for="f1-3">Neither agree nor disagree <input type="radio" id="f1-3" name="field1" value="3"></label>
<label for="f1-4">Agree <input type="radio" id="f1-4" name="field1" value="4"></label>
<label for="f1-5">Strongly Agree <input type="radio" id="f1-5" name="field1" value="5"></label>

It's not really any more complex than a multiple choice. It just depends on what you want to do with the data at the end.

Presumably you'll want to store the info somewhere? How did you want the 'quiz' to work?

Use the same code as for your multiple choice but instead of storing 'correct' or 'incorrect' store the score instead.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Presumably you'll want to store the info somewhere? How did you want the 'quiz' to work?"

The "quiz" is intended as a self-analysis inventory, where the visitor to the website responds to the items, clicks a button, and sees the results, which could be a number score. Then, text would explain what each number means, such as, "A score of such and such means that you are moderately impulsive." So, the data doesn't need to be stored; it's only for the edification of the respondent.

An example of the kind of inventory I'm thinking about can be found at
The trick is figuring out how to return a "score" based on the responses. Since I'm not a programmer, I was hoping someone might be able to offer some suggestions.

Let’s assume that for each quiz item, the score range is from 1 to 5. On some items, “Always” = 1, “Often” = 2, “Sometimes” = 3, “Rarely” = 4, and “Never” = 5. On other items, the scores would be reversed, with “Never” = 1, and so forth.

For simplicity’s sake, let’s suppose we have a two-item quiz. For the first item, "Always" = 1 and "Never" = 5. Then, for the second item, it's reversed: "Always" = 5 and “Never = 1.

If, for example, someone chooses “Never” (= 5) for the first item and “Rarely” (= 2) for the second item, their total score would be 7, which would appear when they click on the “Tally” button.

Could someone show me how such a two-item quiz like that would be coded? Then, I think I can take it from there.

Thanks!
Bill
 
Store a running total of the score in a cookie, then at the end retrieve the value and present the results.

Here's a page that deals with Javascript and cookies...

A quick Google should help you fill in any blanks.

Since you are not a programmer and I think it will lend itself well to this kind of thing might I recommend you take a look at jQuery.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Just for thought and not javasrcipt related really-

I hate that kind of scoring. 5+2 = 2+5 = 3+4 = 4+3. So you have 4 different combinations of scores that mean the same thing? How good can a quiz/test/assessment/webgadget like that be?

I've always made the argument that the "never" in question 1 ought to count for 5, but then the "rarely" in question 2 is really 4 points if you reverse the scale. If what you want is to identify any extremes on the scale you don't want the mechanics and math of the scale canceling things out.

Just an aside. Back to regularly scheduled programming.
 
Thanks, Foamcow, for mentioning jQuery. Whether I end up using it for this application, it's a fascinating subject.

I take it, then, that you don't recommend trying to develop this kind of instrument without some kind of server-side support.

I was hoping someone had seen the kind of inventory I envisioned and could point me to it. I'll keep searching through code libraries, etc. It seemed to me that this application would be pretty generic and oft-used.

BigRed, I'm not sure I'm following your point, or maybe you are misunderstanding what I was getting at.

My intention was to use scores that would be cumulative, not cancel each other out. For example, suppose I wanted to measure someone's meat-eating habits but wanted to balance the questions I ask. So, for "I eat meat..." "Always" would = 5; and for "I eat bread..." "Always" would = 1. The two summed would = 6. Whereas, if the person marked "Rarely" for the second item, the total would = 10, indicating a greater tendency toward meat-eating. (These questions are just an example that came into my head, not intended to be from an actual inventory.)

Does that approach make sense, or am I missing something?

Bill
 
Personally I would do it with a combination of PHP and Javascript but this is a Javascript forum :)

I'd probably use PHP to do any processing on the answers. But that's because I'm more comfortable doing things like this in PHP - where I can control the processing environment.

Javascript is a client side technology, so I'd use it for manipulating the page of questions and the answers. If Javascript wasn't working or available then I'd make sure that things would still work without it (because I'm using PHP to do the donkey work).

I might use Ajax to automatically submit and store each answer as it's made. I might store the results in a database (using MySQL and PHP).

It all depends on how I wanted the app to work and if there were any restriction on the environment.

I see BigRed's point and was going to mention it.

If you are adding the scores together then a 2 in Q1 and a 5 in Q2 would be the same as a 5 in Q1 and a 2 in Q5.
This means that the score for both tests would be 7. Now, how can this mean anything if both tests had different answers yet score the same?

Taking your meat/bread example. What if I said 1 to eating meat and 5 to eating bread. I'd still score 6 but my preference would be the polar opposite of your example.

If using a Likert scale you may also find your results suffer from centre weighting, where people avoid the extremes. You can eliminate this somewhat by only having 4 options of course.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
I see what you mean about the scoring. Back to the drawing board!

Concerning the rest, I feel that I'm getting in way over my head and probably should stick to the simple True/False format that has been working for me.

Bill
 
Hi All,

I wanted to bring some closure to this thread and thank those who provided many useful insights.

On another forum, someone provided me with the following code template, which pretty much does what I had envisioned when I started my quest:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<title>Survey example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Presidential Survey</h1>
<form action= "" method="POST" id="form1">

George W. Bush was a good president:<br />

<span class="answers">
Strongly Disagree
<input type="radio" name="q1" value="1" />
<input type="radio" name="q1" value="2" />
<input type="radio" name="q1" value="3" />
<input type="radio" name="q1" value="4" />
<input type="radio" name="q1" value="5" />
Strongly Agree
</span>

<br />
<br />


Bill Clinton was a good president:<br />

<span class="answers">
Strongly Disagree
<input type="radio" name="q2" value="1" />
<input type="radio" name="q2" value="2" />
<input type="radio" name="q2" value="3" />
<input type="radio" name="q2" value="4" />
<input type="radio" name="q2" value="5" />
Strongly Agree
</span>

<br />
<br />

Abe Lincoln was a good president:<br />

<span class="answers">
Strongly Disagree
<input type="radio" name="q3" value="1" />
<input type="radio" name="q3" value="2" />
<input type="radio" name="q3" value="3" />
<input type="radio" name="q3" value="4" />
<input type="radio" name="q3" value="5" />
Strongly Agree
</span>

</form>

<input type='button' value='score' onclick="score()" />

<script type='text/javascript'>
function el(tid) {return document.getElementById(tid);}

function score(){
var ems = el("form1").elements;
var buff=[], count=0, total=0;

for(var i=0, mx=ems.length;i<mx;i++){
if(ems.checked){ total+=Number(ems.value); count++; }
}
alert("total: "+total+" ; Avg: "+ (total/count).toFixed(1) );
}
</script>
</body>
</html>

I'll certainly keep this code in my archives for future use. However, after all of this searching and discussion, I've decided that for my current purpose, using true/false items makes more sense. For one thing, I can balance the items between those describing one extreme of a trait and those describing the other extreme, which, as was pointed out on this thread, won't work with the five-point scaling.

Also, true-false items will eliminate the progression of responses toward the middle, mentioned in this thread, since respondents have only two choices instead of several.

I've decided that true-false items are sufficient for the informal inventories I'm putting together, since these inventories have only face validity and have not been validated by checking their results against other instruments using a large sample size, etc.

Thanks again for you help.
Bill
 
Good luck in getting what you want done. You can probably use the code you got.

All I was really trying to advocate without sidetracking from actual javascript (which I didn't succeed at) was questions with scales like:

Meat is good:<br />

<span class="answers">
Strongly Disagree
<input type="radio" name="q2" value="1" />
<input type="radio" name="q2" value="2" />
<input type="radio" name="q2" value="3" />
<input type="radio" name="q2" value="4" />
<input type="radio" name="q2" value="5" />
Strongly Agree
</span>

<br />
<br />

Eating meat is nasty:<br />

<span class="answers">
Strongly Disagree
<input type="radio" name="q3" value="5" />
<input type="radio" name="q3" value="4" />
<input type="radio" name="q3" value="3" />
<input type="radio" name="q3" value="2" />
<input type="radio" name="q3" value="1" />
Strongly Agree
</span>


so that the carnivore gets a 10 on this quiz and the vegetarian gets a 2. I thought all you wanted to do was ask some of your questions positively and some negatively (which is the right thing to do). I have just seen that done and then scored in such a way as to cancel things when it is straight totaled with the scale inversion.

HTH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top