PDA

View Full Version : javascript calling a response problem.



pafranklin
07-18-2006, 11:34 PM
:( Hi there, Apologies for the newbie question but I am still learning (big style)!!

I have written a javascript (based on a checkbox addition) and from the resulting score or total I want to be able to select one of three responses. The score or total adds up ok but I cannot seem to trigger one of the response variables.

I have gone through the forums and tutorials but to no avail so Please could someone point me in the right direction??

Firstly here is the script file; -

function load()
{
window.status = "Javascript by "
}

// Insert response to questions answered
var response = new Array(1);
// Insert response
response[0] = "Congratulations if you ticked all of the AGREE boxes."

response[1] ="Often, the first problem to overcome is..... "

response[2] ="If you can be this honest with yourself well done."

function count()
{
var item1price = 10;
var item2price = 1;
var item3price = 0;
var item4price = 10;
var item5price = 1;
var item6price = 0;
var item7price = 10;
var item8price = 1;
var item9price = 0;
var item10price = 10;
var item11price = 1;
var item12price = 0;
var item13price = 10;
var item14price = 1;
var item15price = 0;
var item16price = 10;
var item17price = 1;
var item18price = 0;
var item19price = 10;
var item20price = 1;
var item21price = 0;
var item22price = 10;
var item23price = 1;
var item24price = 0;
var item25price = 10;
var item26price = 1;
var item27price = 0;
var item28price = 10;
var item29price = 1;
var item30price = 0;


// Questions added up PF
if (calc.item1.checked){
var witem1 = document.calc.item1.value = item1price;
} else {
var witem1 = document.calc.item1.value = 0;
}
if (calc.item2.checked){
var witem2 = document.calc.item2.value = item2price;
} else {
var witem2 = document.calc.item2.value = 0;
}
if (calc.item3.checked) {
var witem3 = document.calc.item3.value = item3price;
} else {
var witem3 = document.calc.item3.value = 0;
}
if (calc.item4.checked) {
var witem4 = document.calc.item4.value = item4price;
} else {
var witem4 = document.calc.item4.value = 0;
}
if (calc.item5.checked){
var witem5 = document.calc.item5.value = item5price;
} else {
var witem5 = document.calc.item5.value = 0;
}
if (calc.item6.checked){
var witem6 = document.calc.item6.value = item6price;
} else {
var witem6 = document.calc.item6.value = 0;
}
if (calc.item7.checked) {
var witem7 = document.calc.item7.value = item7price;
} else {
var witem7 = document.calc.item7.value = 0;
}
if (calc.item8.checked) {
var witem8 = document.calc.item8.value = item8price;
} else {
var witem8 = document.calc.item8.value = 0;
}
if (calc.item9.checked){
var witem9 = document.calc.item9.value = item9price;
} else {
var witem9 = document.calc.item9.value = 0;
}
if (calc.item10.checked){
var witem10 = document.calc.item10.value = item10price;
} else {
var witem10 = document.calc.item10.value = 0;
}
if (calc.item11.checked) {
var witem11 = document.calc.item11.value = item11price;
} else {
var witem11 = document.calc.item11.value = 0;
}
if (calc.item12.checked) {
var witem12 = document.calc.item12.value = item12price;
} else {
var witem12 = document.calc.item12.value = 0;
}
if (calc.item13.checked){
var witem13 = document.calc.item13.value = item13price;
} else {
var witem13 = document.calc.item13.value = 0;
}
if (calc.item14.checked){
var witem14 = document.calc.item14.value = item14price;
} else {
var witem14 = document.calc.item14.value = 0;
}
if (calc.item15.checked) {
var witem15 = document.calc.item15.value = item15price;
} else {
var witem15 = document.calc.item15.value = 0;
}
if (calc.item16.checked) {
var witem16 = document.calc.item16.value = item16price;
} else {
var witem16 = document.calc.item16.value = 0;
}
if (calc.item17.checked) {
var witem17 = document.calc.item17.value = item17price;
} else {
var witem17 = document.calc.item17.value = 0;
}
if (calc.item18.checked) {
var witem18 = document.calc.item18.value = item18price;
} else {
var witem18 = document.calc.item18.value = 0;
}
if (calc.item19.checked){
var witem19 = document.calc.item19.value = item19price;
} else {
var witem19 = document.calc.item19.value = 0;
}
if (calc.item20.checked){
var witem20 = document.calc.item20.value = item20price;
} else {
var witem20 = document.calc.item20.value = 0;
}
if (calc.item21.checked) {
var witem21 = document.calc.item21.value = item21price;
} else {
var witem21 = document.calc.item21.value = 0;
}
if (calc.item22.checked) {
var witem22 = document.calc.item22.value = item22price;
} else {
var witem22 = document.calc.item22.value = 0;
}
if (calc.item23.checked){
var witem23 = document.calc.item23.value = item23price;
} else {
var witem23 = document.calc.item23.value = 0;
}
if (calc.item24.checked){
var witem24 = document.calc.item24.value = item24price;
} else {
var witem24 = document.calc.item24.value = 0;
}
if (calc.item25.checked) {
var witem25 = document.calc.item25.value = item25price;
} else {
var witem25 = document.calc.item25.value = 0;
}
if (calc.item26.checked) {
var witem26 = document.calc.item26.value = item26price;
} else {
var witem26 = document.calc.item26.value = 0;
}
if (calc.item27.checked){
var witem27 = document.calc.item27.value = item27price;
} else {
var witem27 = document.calc.item27.value = 0;
}
if (calc.item28.checked){
var witem28 = document.calc.item28.value = item28price;
} else {
var witem28 = document.calc.item28.value = 0;
}
if (calc.item29.checked) {
var witem29 = document.calc.item29.value = item29price;
} else {
var witem29 = document.calc.item29.value = 0;
}
if (calc.item30.checked) {
var witem30 = document.calc.item30.value = item30price;
} else {
var witem30 = document.calc.item30.value = 0;
}

document.calc.pay.value = witem1 + witem2 + witem3 + witem4 + witem5 + witem6 + witem7 + witem8 + witem9 + witem10 + witem11 + witem12 + witem13 + witem14 + witem15 + witem16 + witem17 + witem18 + witem19 + witem20 + witem21 + witem22 + witem23 + witem24 + witem25 + witem26 + witem27 + witem28 + witem29 + witem30;
}

// test the value and input desired resonse
if (pay.value == 100)
{
form.solutions.value = response[0];
}
else if (pay.value > 09)
{
form.solutions.value = response[1];
}
else if (pay.value < 09)
{
form.solutions.value = response[2];
}

If you would like to see the actual HTML page the URL is http://www.emergenceuk.com/test2.html