Help With JavaScript

You can talk about anything here, not necessarily game-related. You may also advertise here.
Post Reply
User avatar
Corban
Forum Maniac
Posts: 348
Joined: Sun Sep 26, 2004 5:19 pm
Location: Kentucky

Post by Corban »

Ok, I'm trying to make this add a set amount of points to the total each time I select a radio button in a new column. Also it needs to be able to subtract it when person changes their choice. Here is the current script. Any help would be much appreciated.

<center><h1>Dr. Phil's Test Personality Test</h1></center>

<script LANGUAGE="JavaScript">

<!-- Begin
function CheckChoice(whichbox)
{
with (whichbox.form)
{
//Handle differently, depending on type of input box.
if (whichbox.type == "radio")
{
//First, back out the prior radio selection's price from the total:
hiddentotal.value = eval(hiddentotal.value) - eval(hiddenpriorradio.value);
//Then, save the current radio selection's price:
hiddenpriorradio.value = eval(whichbox.price);
//Now, apply the current radio selection's price to the total:
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price);
}
else

{
//If box was checked, accumulate the checkbox value as the form total,
//Otherwise, reduce the form total by the checkbox value:
if (whichbox.checked == false)
{ hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value); }
else { hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value); }
}



//Ensure the total never goes negative (some browsers allow radiobutton to be deselected):
if (hiddentotal.value < 0)
{
InitForm();
}

//Now, return with formatted total:
return(formatCurrency(hiddentotal.value));
}
}

//Define function to format a value as currency:
function formatCurrency(num)
{
// Courtesy of http://www7.brinkster.com/cyanide7/
num = num.toString().replace(/\|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
num = Math.floor(num/100).toString();
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '' + num);
}

//Define function to init the form on reload:
function InitForm()
{
//Reset the displayed total on form:
document.myform.total.value='0';
document.myform.hiddentotal.value=0;
document.myform.hiddenpriorradio.value=0;
document.myform2.total.value='0';
document.myform2.hiddentotal.value=0;
document.myform2.hiddenpriorradio.value=0;
document.myform2.hiddenpriorradio.value=0;

//Set all checkboxes and radio buttons on form-1 to unchecked:
for (xx=0; xx < document.myform.elements.length; xx++)
{
if (document.myform.elements[xx].type == 'checkbox' | document.myform.elements[xx].type == 'radio')
{
document.myform.elements[xx].checked = false;
}
}
//Set all checkboxes and radio buttons on form-2 to unchecked:
for (xx=0; xx < document.myform2.elements.length; xx++)
{
if (document.myform2.elements[xx].type == 'checkbox' | document.myform2.elements[xx].type == 'radio')
{
document.myform2.elements[xx].checked = false;
}
}

}

// End -->
</script>

<BODY onLoad="InitForm();" onreset="InitForm();">





<br><br>
Below is Dr. Phil's test. Dr. Phil scored 55; he did this test on Oprah-she got a 38.
Some folks pay a lot of money to find this stuff out. Don't be overly sensitive!
The following is fairly accurate and it should only take couple of minutes.<br><br>


Don't peek but begin the test as you scroll down and answer.
Answers are for who you are now, not who you were in the past.
Have pen or pencil and paper ready.<br>
This is a real test given by the Human Relations Dept, at many of the major corporations
today. It helps them get better insight concerning their employees and prospective employees.<br><br>

It's only 10 simple questions, so grab a pencil and paper,
and keep track of your letter answers for each question. I might change it and have you just click buttons...<br><br>


<h3>Begin...</h3>

<b>1. When do you feel your best?</b><br><br>

<input type="radio" name="question1" value=none price=2
onclick="this.form.total.value=CheckChoice(this);">

a) In the morning.<br><br>

<input type="radio" name="question1" value=duck price=4
onclick="this.form.total.value=CheckChoice(this);">


B) During the afternoon and early evening.<br><br>

<input type="radio" name="question1" value=ginger price=6
onclick="this.form.total.value=CheckChoice(this);">

c) Late at night.<br><br><br>



<b>2. You usually walk...</b><br><br>

<input type="radio" name="question2" value=ginger price=6
onclick="this.form.total.value=CheckChoice(this);">

a) Fairly fast, with long steps.<br><br>

<input type="radio" name="question2" value=ginger price=4
onclick="this.form.total.value=CheckChoice(this);">

B) Fairly fast, with little steps.<br><br>

<input type="radio" name="question2" value=ginger price=7
onclick="this.form.total.value=CheckChoice(this);">

c) Less fast head up, looking the world in the face.<br><br>

<input type="radio" name="question2" value=ginger price=2
onclick="this.form.total.value=CheckChoice(this);">

d) Less fast, head down.<br><br>

<input type="radio" name="question2" value=ginger price=1
onclick="this.form.total.value=CheckChoice(this);">

e) Very slowly.<br><br><br>



<b> 3. When talking to people you...</b><br><br>

a) Stand with your arms folded.<br><br>

B) Have your hands clasped.<br><br>

c) Have one or both your hands on your hips.<br><br>

d) Touch or push the person to whom you are talking.<br><br>

e) Play with your ear, touch your chin, or smooth your hair.<br><br><br>



<b> 4. When relaxing, you sit with... </b><br><br>

a) Your knees bent with your legs neatly side by side.<br><br>

B) Your legs crossed.<br><br>

c) Your legs stretched out or straight.<br><br>

d) One leg curled under you.<br><br><br>



<b>5. When something really amuses you, you react with...</b><br><br>

a) Big appreciated laugh.<br><br>

B) A laugh, but not a loud one.<br><br>

c) A quiet chuckle.<br><br>

d) A sheepish smile.<br><br><br>



<b>6. When you go to a party or social gathering you...</b><br><br>

a) Make a loud entrance so everyone notices you.<br><br>

B) Make a quiet entrance, looking around for someone you know.<br><br>

c) Make the quietest entrance, trying to stay unnoticed.<br><br><br>



<b> 7. You're working very hard, concentrating hard, and you're interrupted...</b><br><br>

a) Welcome the break.<br><br>

B) Feel extremely irritated.<br><br>

c) Vary between these two extremes.<br><br><br>



<b>8. Which of the following colors do you like most?</b><br><br>

a) Red or orange.<br><br>

B) Black.<br><br>

c) Yellow or light blue.<br><br>

d) Green.<br><br>

e) Dark blue or purple.<br><br>

f) White.<br><br>

g) Brown or gray.<br><br><br>



<b>9. When you are in bed at night, in those last few moments before going to sleep you are... </b><br><br>


a) Stretched out on your back.<br><br>

B) Stretched out face down on your stomach.<br><br>

c) On your side, slightly curled.<br><br>

d) With your head on one arm.<br><br>

e) With your head under the covers.<br><br><br>



<b>10. You often dream that you are...</b><br><br>

a) Falling.<br><br>

B) Fighting or struggling.<br><br>

c) Searching for something or somebody.<br><br>

d) Flying or floating.<br><br>

e) You usually have dreamless sleep.<br><br>

f) Your dreams are always pleasant.<br><br><br>

<input type="hidden" name="hiddentotal" value=0>
<input type="hidden" name="hiddenpriorradio" value=0>
<font size=+1>
Your Score: <input type="text" name="total" readonly onFocus="this.blur();">
</font>
<br><br>
</font>



</form>




<h3> POINTS:</h3>

1. (a) 2 (B) 4 © 6<br><br>

2 . (a) 6 (B) 4 © 7 (d) 2 (e) 1<br><br>

3. (a) 4 (B) 2 © 5 (d) 7 (e) 6<br><br>

4. (a) 4 (B) 6 © 2 (d) 1<br><br>

5. (a) 6 (B) 4 © 3 (d) 5 (e) 2<br><br>

6. (a) 6 (B) 4 © 2<br><br>

7. (a) 6 (B) 2 © 4<br><br>

8. (a) 6 (B) 7 © 5 (d) 4 (e) 3 (f) 2 (g) 1<br><br>

9. (a) 7 (B) 6 © 4 (d) 2 (e) 1<br><br>

10. (a ) 4 (B) 2 © 3 (d) 5 (e) 6 (f) 1<br><br>




<br><br>


<b>OVER 60 POINTS:</b> Others see you as someone they should "handle with care." <br>
You're seen as vain, self-centered, and who is extremely dominant. Others may admire you, wishing they could be more like you, but don't always trust you, hesitating to become too deeply involved with you.
<br><br>


<b>51 TO 60 POINTS:</b> Others see you as an exciting, highly volatile, rather impulsive personality; a natural leader, who's quick to make decisions, though not always the right ones. They see you as bold and adventuresome, someone who will try anything once; someone who takes chances and enjoys an adventure. They enjoy being in your company because of the excitement you radiate.
<br><br>

<b>41 TO 50 POINTS:</b> Others see you as fresh, lively, charming, amusing, practical, and always interesting; someone who's constantly in the center of attention, but sufficiently well-balanced not to let it go to their head. They also see you as kind, considerate, and understanding; someone who'll always cheer them up and help them out.

<br><br>

<b>31 TO 40 POINTS:</b> Others see you as sensible, cautious, careful and practical. They see you as clever, gifted, or talented, but modest. Not a person who makes friends too quickly or easily, but someone who's extremely loyal to friends you do make and who expect the same loyalty in return. Those who really get to know you realize it takes a lot to shake your trust in your friends, but equally that it takes you a long time to get over if that trust is ever broken.
<br><br>


<b>21 TO 30 POINTS:</b> Your friends see you as painstaking and fussy. They see you as very cautious, extremely careful, a slow and steady plodder. It would really surprise them if you ever did something impulsively or on the spur of the moment, expecting you to examine everything carefully from every angle and then, usually decide against it. They think this reaction is caused partly by your careful nature.
<br><br>


<b>UNDER 21 POINTS:</b> People think you are shy, nervous, and indecisive, someone who needs looking after, who always wants someone else to make the decisions and who doesn't want to get involved with anyone or anything! They see you as a worrier who always sees problems that don't exist. Some people think you're boring. Only those who know you well know that you aren't.
<br><br>
Formerly LordBrockFreak
http://www.audioscrobbler.com/user/Corban/
"We're closer now than we've ever been to finishing." ~The Beatles
User avatar
Devari
Mr. -1
Posts: 3194
Joined: Wed Mar 10, 2004 5:02 am
Location: British Columbia, Canada

Post by Devari »

I'm not a JS user, but I will tell you: the topic title is misleading. I'm changing it to Java - there is quite a big difference.

http://en.wikipedia.org/wiki/Javascript

vs.

http://en.wikipedia.org/wiki/Java

By the way, if I remember correctly, Beatles is a JS wizard. You might be able to ask him.
If you go down to the woods today, you better not go alone
It's a lovely day in the woods today, but safer to stay at home
BECAUSE EVIL FREEN IS KILLING ALL THE TEDDY BEARS AT THEIR PICNIC
User avatar
Corban
Forum Maniac
Posts: 348
Joined: Sun Sep 26, 2004 5:19 pm
Location: Kentucky

Post by Corban »

Thank you for the help. I believe after seeing all the obstacles of using other people scripts I think I should at least learn the basics of the main scripting languages. Would it be a better use of my time to learn JavaScript or php first? Most of the scripts I use now are just modified from free script sources. Also do you know a good manual for learning either of these?
Formerly LordBrockFreak
http://www.audioscrobbler.com/user/Corban/
"We're closer now than we've ever been to finishing." ~The Beatles
Post Reply
  • Members connected in real time

    🔒 Close the panel of connected members