www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: How do I use JavaScript to calculate forms

  1. #16
    Join Date
    Jun 2012
    Posts
    14
    Quote Originally Posted by JMRKER View Post
    If this project is taking so much memory and printout, how about showing what you are using.
    This is the code I got by modifying what James Alarie posted. Running the program with Internet Explorer and choosing the 1st answer for each question gives a = 2 with every other letter being 0. It seems that you can give the same letter's answer for all 13 questions and the results is 2 answers for that letter and 0 answers for all other letters. If you answer the questions a b c d e f a b c d e f a you get a = 1, b = 1 and 0 for every other letter.

    I don't know yet how I will score the test but chances are the score will depend on how many questions are answered. The program will need a mechanism to account for when someone doesn't give an answer for a question- either make them give an answer or change the final calculation of the score.

    I am using wordpad to write the code and saving the files as text with the .html.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>

    <title>Calculate Forms</title>
    <!--- http://www.webdeveloper.com/forum/sh...d.php?t=261564 --->

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Language" content="en-US" />
    <meta name="Author" content="James Alarie - jalarie@umich.edu" />
    <meta name="description" content="How to Calculate Forms." />
    <meta name="keywords" content="calculate,form" />

    <link rel="icon" href="favicon.ico" />
    <link rev="made" href="mailto:jalarie@umich.edu" />

    <!--
    Author: James Alarie
    Company: -independent-
    Address: 3391 N Genesee Rd
    Flint MI 48506
    Latitude: 42.9663 Longitude: -83.7769
    Telephone: +1-810-736-8259
    Fax: -none-
    Web Site: http://spruce.flint.umich.edu/~jalarie/
    E-Mail: jalarie@umich.edu
    Comments: Having said that, I've probably told you more than I know.
    -->

    <link href="style1.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    /*<![CDATA[*/
    /*]]>*/
    </style>

    <script type="text/javascript" src="style1.js"></script>
    <script type="text/javascript">
    /*<![CDATA[*/

    function CalcIt() {
    f1=document.forms[0]; // abbreviation
    R1V='';
    R2V='';
    R3V='';
    R4V='';
    R5V='';
    R6V='';
    R7V='';
    R8V='';
    R9V='';
    R10V='';
    R11V='';
    R12V='';
    R132V='';
    // add R3V through R13V here
    aCount=0;
    bCount=0;
    cCount=0;
    dCount=0;
    eCount=0;
    fCount=0;
    for (ix1=0; ix1< f1.R1.length; ix1++) {
    if (f1.R1[ix1].checked) {
    R1V=f1.R1[ix1].value;
    }
    }
    for (ix1=0; ix1< f1.R2.length; ix1++) {
    if (f1.R2[ix1].checked) {
    R2V=f1.R2[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R3.length; ix1++) {
    if (f1.R3[ix1].checked) {
    R3V=f1.R3[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R4.length; ix1++) {
    if (f1.R4[ix1].checked) {
    R4V=f1.R4[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R5.length; ix1++) {
    if (f1.R5[ix1].checked) {
    R5V=f1.R5[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R6.length; ix1++) {
    if (f1.R6[ix1].checked) {
    R6V=f1.R6[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R7.length; ix1++) {
    if (f1.R7[ix1].checked) {
    R7V=f1.R7[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R8.length; ix1++) {
    if (f1.R8[ix1].checked) {
    R8V=f1.R8[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R9.length; ix1++) {
    if (f1.R9[ix1].checked) {
    R9V=f1.R9[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R10.length; ix1++) {
    if (f1.R10[ix1].checked) {
    R10V=f1.R10[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R11.length; ix1++) {
    if (f1.R11[ix1].checked) {
    R11V=f1.R11[ix1].value;
    }
    }
    for (ix1=0; ix1< f1.R12.length; ix1++) {
    if (f1.R12[ix1].checked) {
    R12V=f1.R12[ix1].value;
    }
    }

    for (ix1=0; ix1< f1.R13.length; ix1++) {
    if (f1.R13[ix1].checked) {
    R13V=f1.R13[ix1].value;
    }
    }
    // add 3 through 13 'for ...' sets of 5 lines each here

  2. #17
    Join Date
    Jun 2012
    Posts
    14
    if (R1V == 'a') { aCount+=1; }
    if (R1V == 'b') { bCount+=1; }
    if (R1V == 'c') { cCount+=1; }
    if (R1V == 'd') { dCount+=1; }
    if (R1V == 'e') { eCount+=1; }
    if (R1V == 'f') { fCount+=1; }
    if (R2V == 'a') { aCount+=1; }
    if (R2V == 'b') { bCount+=1; }
    if (R2V == 'c') { cCount+=1; }
    if (R2V == 'd') { dCount+=1; }
    if (R2V == 'e') { eCount+=1; }
    if (R2V == 'f') { fCount+=1; }
    Out ='';
    Out+='a='+aCount+'\n';
    Out+='b='+bCount+'\n';
    Out+='c='+cCount+'\n';
    Out+='d='+dCount+'\n';
    Out+='e='+eCount+'\n';
    Out+='f='+fCount+'\n';
    alert(Out);
    return true;
    } CalcIt

    /*]]>*/
    </script>

    </head>

    <body class="body1">
    <div id="body">
    <!-- Page Header -->
    <div id="header">
    <h1>Calculate Forms</h1>
    <hr />
    </div>

    <!-- Content -->
    <div id="content">
    <br />
    <noscript>
    <p class="notice">
    You must have scripting enabled to make full use of this page.
    </p>
    </noscript>

    <div class="center">
    <form method="post" action="javascript:void(0);" onsubmit="CalcIt();">
    <div class="form">

    <label for="Q1"><font face="Bookman Old Style" size ="3" color="blue">01. What is your view of property?</font></label>&nbsp;&nbsp;<br>
    <input type="radio" name="R1" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Most property should be privately owned as a life-trust, but since property equals power society has a right to regulate private property to insure that it is acquired by honest means; that is not used in ways that brings harm to or infringe on the rights of others and that it is used in ways that insure its usefulness to future generations.
    </font>
    <br>
    <input type="radio" name="R1" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    All property should be privately owned and individuals have a right to acquire and use property as they see fit without regulation of any kind so that they may maximize their own material benefit.
    </font>
    <br>
    <input type="radio" name="R1" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Most property should be privately owned, but society has an obligation to regulate private property to the extent necessary to insure that no segment of society is lacking in essential material security- food, shelter, healthcare, education, et cetera.
    </font>
    <br>
    <input type="radio" name="R1" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Most property should be privately owned, but the government has an obligation to regulate private property to insure that it is used in a way that benefits the nation-state.
    </font>
    <br>
    <input type="radio" name="R1" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Most property should be publicly owned to insure that all segments of society have adequate material possessions before anybody has an excess.
    </font>

  3. #18
    Join Date
    Jun 2012
    Posts
    14
    <br>
    <input type="radio" name="R1" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Private property must not exist and every member of society has an obligation to labor as much as they can in order to insure that everyone in society has their material needs met.
    </font>
    <br>
    <label for="Q2">
    <font face="Bookman Old Style" size ="3" color="blue">
    02. What is the relationship between society and the individual members of society in terms of economic/material security?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R2" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Individuals have a moral obligation to first look out for themselves and their families so they do not become a burden on society and second to provide the less fortunate members of society with whatever material assistance they can provide in order to stave off the mass concentration of poverty that can foment social upheaval, but such assistance must not create a social class that is dependent on handouts from others or leads to the disruption of the family unit or the displacement of traditional sources of charity or otherwise causes societal upheaval, and this obligation can be codified by law only when the private sector proves to be inadequate.
    </font>
    <br>
    <input type="radio" name="R2" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The individual has no obligation to society, i.e., society does not exist since no individual has a right to expect others to provide for him.
    </font>
    <br>
    <input type="radio" name="R2" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Society has the right to obligate individuals to provide material help to the less fortunate to insure that everyone has a minimum standard of living.
    </font>
    <br>
    <input type="radio" name="R2" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Individuals can provide private charity to other members of society as they wish, but the nation-state may impose a legal obligation on individuals so that the national community can provide for the essential material wellbeing of all members of society thereby obligate all individuals in society to provide service to benefit the nation-state.
    </font>
    <br>
    <input type="radio" name="R2" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    At the sole direction of the government society must be the individual’s primary source of material well-being, and individuals owe their primary allegiance to society in that they must contribute to society so that society can meet the essential material needs of each of its members before any individual has a right to accumulate an excess of material possessions.
    </font>
    <br>
    <input type="radio" name="R2" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The individual has total obligation to society and society has an ironclad obligation to each of its individuals to the extent that society does not exist because all individuals are socially and economically equal.
    </font>
    <br>
    <label for="Q3">
    <font face="Bookman Old Style" size ="3" color="blue">
    03. When it comes to material gain
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R3" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Individuals should be free to maximize their individual material gain according to free market forces, but human nature requires that individual behavior must be regulated by society/government to insure that individuals do not engage in unfair, fraudulent or otherwise dishonest behavior, and material gain for future generations should never be sacrificed for the sake of maximizing material gain in the present.
    </font>
    <br>

  4. #19
    Join Date
    Jun 2012
    Posts
    14
    <input type="radio" name="R3" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Each individual should be allowed to maximize their personal material gain as quickly as possible without any interference from others since this is the most efficient way to insure that all individuals can and will maximize their personal individual gain.
    </font>
    <br>
    <input type="radio" name="R3" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Society, through governmental mechanism, should regulate material gain to insure equality between individuals as far as their basic economic needs are concerned.
    </font>
    <br>
    <input type="radio" name="R3" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Individuals are free to pursue material gain under sufficient regulation to insure that such gain benefits the nation state as a whole.
    </font>
    <br>
    <input type="radio" name="R3" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Society, through governmental mechanisms, should heavily regulate material gain on the part of the individual so that the personal gain of one individual cannot deplete resources needed to provide another individual with basic sustenance.
    </font>
    <br>
    <input type="radio" name="R3" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Material gain for the individual must not be allowed since the struggle for individual material gain leads to inequality within society.
    </font>
    <br>
    <label for="Q4">
    <font face="Bookman Old Style" size ="3" color="blue">
    04. What is the purpose of sex, marriage and the family?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R4" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Marriage, consisting of one man legally, and physically joined for life to one woman is of paramount importance as the foundation of the family unit which is in turn the foundation for a stable, functional and self-perpetuating society in that it is the only setting in which sex can properly exist and children can be properly produced and reared and therefore society has a right to regulate sex and marriage to insure its own survival.
    </font>
    <br>
    <input type="radio" name="R4" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Marriage is of no importance except to the people who wish to make a contractual agreement with each other regarding sex and marriage, and since it has no legal basis of any kind neither society, nor the government has any right to regulate it.
    </font>
    <br>
    <input type="radio" name="R4" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Marriage is of no importance except to the people who wish to be married, and as a
    voluntary legal and physical union of people for the purpose of sex and procreation it needs neither legal, nor moral sanction, but to the extent that such sanction is given all persons who wish to engage in sexual behavior and be married must be treated equally before the law.
    </font>
    <br>
    <input type="radio" name="R4" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state has the right to regulate and encourage marriage and procreation in order to facilitate the nation’s struggle to attain greatness.
    </font>
    <br>
    <input type="radio" name="R4" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Marriage is of no importance except to the people who wish to be married, and as a
    voluntary legal and physical union of people for the purpose of sex and procreation it does not need legal or moral sanction and shall receive neither by either society or the government.
    </font>
    <br>
    <input type="radio" name="R4" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Marriage is a means whereby the rich and powerful can oppress the poor and weak. It has no purpose in and should have no sanction by an equitable society.
    </font>
    <br>
    <label for="Q5">
    <font face="Bookman Old Style" size ="3" color="blue">
    05. In your view economic markets-
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R5" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should be regulated by the government only to the extent necessary to prevent monopolies, fraud and other dishonest trade practices while protecting consumers from the effects of asymmetric information.
    </font>
    <br>
    <input type="radio" name="R5" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should not have any regulation apart from the natural laws of supply and demand and buyer beware.
    </font>
    <br>
    <input type="radio" name="R5" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should be regulated by the government to the extent necessary to insure the economic equality between individuals.
    </font>
    <br>
    <input type="radio" name="R5" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should be subject to the laws of supply and demand but under heavy government regulation to insure that the nation’s needs are met.
    </font>
    <br>
    <input type="radio" name="R5" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should be placed under the regulation of government managers who will determine the type and quantity of goods and services that will be produced and consumed so that everyone’s basic needs are met.
    </font>
    <br>
    <input type="radio" name="R5" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Have no need of regulation because the market is simply the equitable exchange of goods and services so that everyone gets what they need and contributes what they can.
    </font>
    <br>
    <label for="Q6">
    <font face="Bookman Old Style" size ="3" color="blue">
    06. In you view how does socio-economic competition work-
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R6" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Human beings, when left to their own devices are self-centered, self-serving, greedy beings and thus must be restrained by societal forces (government, religion, social mores etcetera) so their individual actions cannot harms others or otherwise disrupt society.
    </font>
    <br>

  5. #20
    Join Date
    Jun 2012
    Posts
    14
    <input type="radio" name="R6" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Human beings, as rational creatures, will naturally complete with each other in a fair manner to maximize their individual self-interests in that the possibility of economic retaliation or civil lawsuits will insure each individual’s honesty.
    </font>
    <br>
    <input type="radio" name="R6" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Government should do whatever is necessary to insulate individual human beings from the factors of life that create inequality and hardship caused by circumstance and competition.
    </font>
    <br>
    <input type="radio" name="R6" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Competition is necessary to eliminate the weak and unproductive that would otherwise drain society’s resources and thereby be detrimental to the strength and power of the nation state.
    </font>
    <br>
    <input type="radio" name="R6" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Government regulation is necessary to insure that society maintains equality between individual human beings by cooperating with each other in the manner necessary to maintain an equitable society.
    </font>
    <br>
    <input type="radio" name="R6" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Competition of any kind is disruptive and unnecessary since human beings, when free of oppression, will freely cooperate with each other in order to maximize their collective self-interests.
    </font>
    <br>
    <label for="Q7">
    <font face="Bookman Old Style" size ="3" color="blue">
    07. What is the purpose of a nation state?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R7" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state has paramount importance as a unifying and assimilating mechanism for people who share or choose to share a common language, culture and heritage which are not necessarily dependent on biological factors such as race or ethnicity, and in order to maintain these functions a nation state must maintain its sovereignty and its freedom of action and must not be constrained by other nation states or international entities.
    </font>
    <br>
    <input type="radio" name="R7" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state merely exists as a means of justifying the existence of government and government exists simply to deprive individuals of their life, liberty and property.
    </font>
    <br>
    <input type="radio" name="R7" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state has historically preserved people who share a common identity by promoting conflict with other nation states who have an equal right to exist so nation states should not have the freedom to act on their own volition so that international conflict can be reduced.
    </font>
    <br>
    <input type="radio" name="R7" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state exists as a mechanism to organize and manage a people who have a common identity in order to direct them to greatness by competing with other nation states.
    </font>
    <br>
    <input type="radio" name="R7" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Is a by-product of history that used to preserve a people who have a common identity, but which is now evolving to become simply a mechanism by which natural resources and economic activity can be managed in order to insure equality among people and the sooner this evolution is complete the sooner the people of the world will live in peace with each other.
    </font>
    <br>
    <input type="radio" name="R7" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state is merely a mechanism by which the rich and powerful can oppress the poor and weak while creating tension and conflict among the world’s peoples so that the powers that be in each nation can have an excuse for seizing the resources of other nations in the name of patriotism and thus the nation state should be abolished.
    </font>
    <br>
    <label for="Q8">
    <font face="Bookman Old Style" size ="3" color="blue">
    08. What is the purpose of government?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R8" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Government is necessary for the preservation of a stable, functioning and self-perpetuating society in that it is an unbiased referee for settling societal disputes while it maintains public order and performs whatever other tasks that must be done when the private sector either cannot or will not perform them.
    </font>
    <br>
    <input type="radio" name="R8" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The government has no legitimate purpose and its existence is merely as a source of oppression to restrain people’s liberty to conduct their lives as they see fit in order to maintain their own self-interests. Rational people inter-acting with other to maintain their own personal self-interest is sufficient to maintain order.
    </font>
    <br>
    <input type="radio" name="R8" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The government’s purpose is to serve as the mechanism for regulating society’s resources so that they can be used to promote equality between society’s members.
    </font>
    <br>
    <input type="radio" name="R8" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Must have enough power to marshal the nation’s people and resources in order to compete with other nations and thereby achieve greatness.
    </font>
    <br>
    <input type="radio" name="R8" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Must have enough power to marshal society’s resources so they can be used to insure equality between society’s members.
    </font>
    <br>
    <input type="radio" name="R8" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Is unnecessary and serves only to empower people and institutions that wish to profit by oppressing others for the sake of personal gain.
    </font>
    <br>
    <label for="Q9">
    <font face="Bookman Old Style" size ="3" color="blue">
    09. Force (physical, economic, emotional etcetera):
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R9" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Is always legitimate when used by society (or by individuals when society cannot take action in a timely manner) to preserve, protect and defend human life, liberty and property from criminal aggression, but under no circumstances should force be used to endanger society or disrupt the operation of a legitimate government that can be altered by the normal course of political means.
    </font>
    <br>
    <input type="radio" name="R9" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Can always be used by individuals to preserve, protect and defend human life, liberty and property against aggression of any kind.
    </font>
    <br>
    <input type="radio" name="R9" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should never be necessary in an ideal setting, but when necessary it should always be applied by society, and not by individuals.
    </font>
    <br>
    <input type="radio" name="R9" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    No individual is entitled to use force for any reason lest they disrupt society and the nation state.
    </font>
    <br>
    <input type="radio" name="R9" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Should be applied by the state whenever necessary to maintain an equitable and just society, but should never be used by individuals either against other individuals or to disrupt the operation of the state.
    </font>
    <br>
    <input type="radio" name="R9" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    May be used by individuals to achieve justice whenever society fails to provide them with justice, but it should not be used otherwise by individuals and it should be used only sparingly by society lest its application lead to injustice.
    </font>
    <br>
    <label for="Q10">
    <font face="Bookman Old Style" size ="3" color="blue">
    10. What is your view on using natural resources?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R10" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Individual owners are entitled to use their natural resources but only with the understanding that natural resources are given to each generation as a trust by the generations that have come before it, and while each generation is entitled to benefit by using natural resources they have a moral obligation, that can be mandated by law when necessary, to do so in the most sustainable manner possible so natural resources are conserved for future generations.
    </font>
    <br>
    <input type="radio" name="R10" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    People who own natural resources must be allowed to use them as they see fit for their own personal gain without restrictions of any kind.
    </font>
    <br>
    <input type="radio" name="R10" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Individual owners should be allowed to use their natural resources providing that society may legally regulate how they are used for the sake of making resources available to the less fortunate members of society.
    </font>

  6. #21
    Join Date
    Jun 2012
    Posts
    14
    <br>
    <input type="radio" name="R10" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Natural resources should be used in the manner that most benefits the members of society on an equal basis and to this end the government should manage how they are used.
    </font>
    <br>
    <input type="radio" name="R10" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    While individual owners are entitled to make a profit from the use of natural resources, the government should be solely responsible for deciding how to use natural resources so they may contribute to the nation state’s struggle to achieve greatness.
    </font>
    <br>
    <input type="radio" name="R10" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Natural resources have no owner other than the people and they should be used as the people see fit.
    </font>
    <br>
    <label for="Q11">
    <font face="Bookman Old Style" size ="3" color="blue">
    11. What is your view of abortion?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R11" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Society must always uphold the sanctity of human life so abortion for any reason other than to preserve the life of a pregnant woman is murder and by allowing sex without consequences abortion encourages the destruction of marriage and thereby threatens the family unit and the foundation of society.
    </font>
    <br>
    <input type="radio" name="R11" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Abortion is merely an individual’s choice that must be neither mandated, nor restricted by any means.
    </font>
    <br>
    <input type="radio" name="R11" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Abortion is an individual’s choice and it must not be restricted by law.
    </font>
    <br>
    <input type="radio" name="R11" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Abortion is an individual’s choice but in some circumstances it may be necessary to mandate abortion when a society’s economic or natural resources cannot support a larger population.
    </font>
    <br>
    <input type="radio" name="R11" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The nation state can mandate and restrict abortion as necessary to maintain the nation’s power.
    </font>
    <br>
    <input type="radio" name="R11" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Abortion is an individual’s choice that may sometimes be necessary when society is unable to sustain a larger population.
    </font>
    <br>
    <label for="Q12">
    <font face="Bookman Old Style" size ="3" color="blue">
    12. What is your view of religion?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R12" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Religion, regardless of what form it takes, is of vital importance to society when practiced in a peaceful manner, because it acts as a break on human nature and provides a stabilizing influence on society and to this end the society and the government should respect people’s religious heritage while at the same time respecting freedom of conscience for the individual and not restricting the peaceful exercise of religion or abridging the human, constitutional or civil rights of any religious community or excluding anyone from public life on account of their religion for the sake of avoiding sectarian strife that can disrupt society and thereby endanger people’s rights to life, liberty and property.
    </font>
    <br>
    <input type="radio" name="R12" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Religion has no importance except to individuals who wish to practice it, and it can only be legitimately practiced solely as a private matter so that society has no right to regulate religion and nobody has a right to impose their religion on others in any manner whatsoever.
    </font>
    <br>
    <input type="radio" name="R12" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Religion has no importance except to individuals who wish to practice it as a solely private matter to the extent that government can regulate religion to insure that all religions are equal before the law and nobody uses their religion to influence society or the government.
    </font>
    <br>
    <input type="radio" name="R12" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Religion can be a useful tool for promoting a national identity and insuring loyalty and allegiance to the nation state so government has the authority and even the duty to regulate and mandate religion to promote national greatness.
    </font>
    <br>
    <input type="radio" name="R12" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Religion is a source of conflict that may disrupt society and thereby make it difficult to use natural and economic resources in an efficient and equitable manner and to this end religion should be regulated by the government to the extend necessary to make it completely a private matter
    </font>
    <br>
    <input type="radio" name="R12" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Religion is only a tool of oppression whereby the rich and powerful can compel the poor and weak to do their bidding and thus religion should be totally abolished.
    </font>
    <br>
    <label for="Q13">
    <font face="Bookman Old Style" size ="3" color="blue">
    13. What is your view of the inter-relationship between men and women?
    </font>
    </label>&nbsp;&nbsp;<br>
    <input type="radio" name="R13" value="a" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Men and women are biologically different and this gives each of them naturally distinct functions in society that makes them mutually dependent on each other for the sake of producing and rearing children and thereby preserving society, and any effort to change or mix these natural functions is detrimental to society so society therefore has a right to uphold the differences between men and women.
    </font>
    <br>
    <input type="radio" name="R13" value="b" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Men and women should be free to do as they please without any interference from anyone.
    </font>
    <br>
    <input type="radio" name="R13" value="c" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The equality of men and women must be mandated by law so nobody can be stifled by traditional sex roles.
    </font>
    <br>
    <input type="radio" name="R13" value="d" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Men and women are biologically different and this gives each of them naturally distinct functions that that nation state can use in its struggle to achieve greatness and which the nation state must mandate by law.
    </font>
    <br>
    <input type="radio" name="R13" value="e" />
    <font face="Bookman Old Style" size ="2" color="blue">
    The equality of men and women must be mandated by law and the government must take steps to give women the opportunity to overcome oppression and assume non-traditional sex roles.
    </font>
    <br>
    <input type="radio" name="R13" value="f" />
    <font face="Bookman Old Style" size ="2" color="blue">
    Men and women must be free to exercise their natural abilities so they can equally contribute to society.
    </font>
    <br>

    <input type="submit" value="Submit" title="Submit" />&nbsp;
    <input type="reset" value="Reset" title="Reset" />&nbsp;
    </div><!-- form -->
    </form>

    </div><!-- center -->

    </div>

    <!-- Page Footer -->
    <div id="footer">
    <br clear="all" /><hr />
    Written on June 12, 2012, by:&nbsp;
    <a href="mailto:jalarie@umich.edu">James Alarie</a>.
    </div>

    </div>
    </body>

    </html>

  7. #22
    Join Date
    Jun 2012
    Posts
    14
    Quote Originally Posted by xelawho View Post
    right. in that case it would make sense to store your questions and answers in objects, put them in an array and loop through them. This one outputs numbers instead of letters (lazy coding, but makes it simpler) - that's OK isn't it?
    I’ve added the 2nd question and its answers to the code:

    var questions=[{que:”What is the relationship between society and the individual members of society in terms of economic/material security?”,ans:["A. Most property should be privately owned as a life-trust, but since property equals power society has a right to regulate private property to insure that it is acquired by honest means; that is not used in ways that brings harm to or infringe on the rights of others and that it is used in ways that insure its usefulness to future generations.",
    “B. All property should be privately owned and individuals have a right to acquire and use property as they see fit without regulation of any kind so that they may maximize their own material benefit.”,
    “C. Most property should be privately owned, but society has an obligation to regulate private property to the extent necessary to insure that no segment of society is lacking in essential material security- food, shelter, healthcare, education, et cetera.”,
    “D. Most property should be privately owned, but the government has an obligation to regulate private property to insure that it is used in a way that benefits the nation-state.”,
    “E. Most property should be publicly owned to insure that all segments of society have adequate material possessions before anybody has an excess.”,
    “F. Private property must not exist and every member of society has an obligation to labor as much as they can in order to insure that everyone in society has their material needs met.”]}]


    Now all I get is the box for check scores. Even what you added for the 1st question and answers is gone.

  8. #23
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,373

    Lightbulb

    I would suggest you break your question/response displays apart from your script.
    To that end, try this, saved as two files in the same directory.

    Questions.html
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
    
    <title>Calculate Forms</title>
    <!--- http://www.webdeveloper.com/forum/showthread.php?t=261564 --->
    
    <script type="text/javascript" src="Questions.js"></script>
    
    <script type="text/javascript">
    
    function getRBtnName(GrpName) {
      var sel = document.getElementsByName(GrpName);
      var fnd = -1;
      var str = '';
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
      }
    //  return fnd;   // return option index of selection
    // comment out next line if option index used in line above  
      return str;
    } 
    
    var Responses = ' abcdef';
    var Counts = [0,0,0,0,0,0,0,0,0,0,0,0,0];
    
      function CalcIt() {
        Counts = [0,0,0,0,0,0,0,0,0,0,0,0,0];
        var resp = '';
        for (var i=0; i<Questions.length; i++) {
          resp = getRBtnName('R'+i);
          if (resp != '') {
            posn = Responses.indexOf(resp);
            Counts[posn]++;
          }
        }
        Out ='';
        for (var i=1; i<Responses.length; i++) {
          Out += Responses.charAt(i)+' = '+Counts[i]+'\n';
        }
        alert(Out);
        return true;
      } // CalcIt
    
    </script>
    
    </head>
    
      <body class="body1">
       <div id="body">
    <!-- Page Header -->
        <div id="header">
          <h1>Calculate Forms</h1>
          <hr />
        </div>
    
    <!-- Content -->
        <div id="content">
          <br />
          <noscript>
            <p class="notice">
              You must have scripting enabled to make full use of this page.
            </p>
          </noscript>
          
          <div class="center">
            <form method="post" action="javascript:void(0);" onsubmit="CalcIt();">
             <div class="form">
    
    <script type="text/javascript">
    var str = '';
    for (var i=0; i<Questions.length; i++) {
      str += '<b style="font-size:1.2em">'+Questions[i][0]+'</b><br>';
      for (var j=1; j<Questions[i].length; j++) {
        str += '<input type="radio" name="R'+i+'" value="'+Responses.charAt(j)+'" /> ';
        str += Questions[i][j]+'<br>';
      }
      str += '<p />';
    }
    document.write(str);
    </script>
    
              <input type="submit" value="Submit" title="Submit" />&nbsp;
              <input type="reset" value="Reset" title="Reset" />&nbsp; 
             </div><!-- form -->
            </form>
          </div><!-- center -->
        </div>
      
    <!-- Page Footer -->
        <div id="footer">
          <br clear="all" /><hr />
          Written on June 12, 2012, by:&nbsp;
          <a href="mailto:jalarie@umich.edu">James Alarie</a>.
          Modified by: jmrker
        </div>
    
       </div>
      </body>
    
    </html>
    Questions.js
    Code:
    var Questions = [
      ['Question 1: What is your view of property?',
      'A. Most property should be privately owned as a life-trust,'
       +' but since property equals power society has a right to regulate private property to insure that it is acquired by honest means;'
       +' that is not used in ways that brings harm to or infringe on the rights of others and that it is used in ways that insure'
       +' its usefulness to future generations.',
      'B. All property should be privately owned and individuals have a right to acquire and use property as they see fit without regulation'
       +' of any kind so that they may maximize their own material benefit.',
      'C. Most property should be privately owned, but society has an obligation to regulate private property to the extent necessary'
       +' to insure that no segment of society is lacking in essential material security- food, shelter, healthcare, education, et cetera.',
      'D. Most property should be privately owned, but the government has an obligation to regulate private property'
       +' to insure that it is used in a way that benefits the nation-state.',
      'E. Most property should be publicly owned to insure that all segments of society have adequate material possessions'
       +' before anybody has an excess.',
      'F. Private property must not exist and every member of society has an obligation to labor as much as they can'
       +' in order to insure that everyone in society has their material needs met.'],
    
      ['Question 2: What is the relationship between society and the individual members of society in terms of economic/material security?',
      'A. Individuals have a moral obligation to first look out for themselves and their families so they do not become a burden on society and second to provide the less fortunate members of society with whatever material assistance they can provide in order to stave off the mass concentration of poverty that can foment social upheaval, but such assistance must not create a social class that is dependent on handouts from others or leads to the disruption of the family unit or the displacement of traditional sources of charity or otherwise causes societal upheaval, and this obligation can be codified by law only when the private sector proves to be inadequate.',
      'B. The individual has no obligation to society, i.e., society does not exist since no individual has a right to expect others to provide for him.',
      'C. Society has the right to obligate individuals to provide material help to the less fortunate to insure that everyone has a minimum standard of  living.',
      'D. Individuals can provide private charity to other members of society as they wish, but the nation-state may impose a legal obligation on individuals so that the national community can provide for the essential material wellbeing of all members of society thereby obligate all individuals in society to provide service to benefit the nation-state.',
      'E. At the sole direction of the government society must be the individual’s primary source of material well-being, and individuals owe their primary allegiance to society in that they must contribute to society so that society can meet the essential material needs of each of its members before any individual has a right to accumulate an excess of material possessions.',
      'F. The individual has total obligation to society and society has an ironclad obligation to each of its individuals to the extent that society does not exist because all individuals are socially and economically equal.'],
      
      ['Question 3: When it comes to material gain',
      'A. Individuals should be free to maximize their individual material gain according to free market forces, but human nature requires that individual behavior must be regulated by society/government to insure that individuals do not engage in unfair, fraudulent or otherwise dishonest behavior, and material gain for future generations should never be sacrificed for the sake of maximizing material gain in the present.',
      'B. Each individual should be allowed to maximize their personal material gain as quickly as possible without any interference from others since this is the most efficient way to insure that all individuals can and will maximize their personal individual gain.',
      'C. Society, through governmental mechanism, should regulate material gain to insure equality between individuals as far as their basic economic needs are concerned.',
      'D. Individuals are free to pursue material gain under sufficient regulation to insure that such gain benefits the nation state as a whole.',
      'E. Society, through governmental mechanisms, should heavily regulate material gain on the part of the individual so that the personal gain of one individual cannot deplete resources needed to provide another individual with basic sustenance.',
      'F. Material gain for the individual must not be allowed since the struggle for individual material gain leads to inequality within society.'],
      
      ['Question 4', 'A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 5', 'A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 6', 'A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 7', 'A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 8', 'A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 9', 'A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 10','A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 11','A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 12','A. ','B. ','C. ','D. ','E. ','F. '],
      ['Question 13','A. ','B. ','C. ','D. ','E. ','F. ']
    ];
    Note the two different methods of entering the questions/responses in the Questions.js file
    If you separate the two functions, you could develop a second questionaire and still use the script to display them and score.

    Scoring will be your next problem, but at least you can collect the data.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles