Two Forms One HTMarriage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rich

    #1

    Two Forms One HTMarriage

    Hello,

    I've been trying to teach myself JavaScript via a book and a number of
    JavaScript Tutorials Online. I have more understanding of what I am doing,
    although definetly not has much as what I have read on this newsgroup.

    I'm trying to learn a new skill in order to hopefully get a job. My job went
    to india while I was out on medical leave (carpal tunnel.)

    My question, I have two JavaScript / Htm pages identical to the one below.
    I'm trying to figure out how I could put both of these "identical"
    javascript pages into One HTM page. But I am clueless as to what to look
    for and or how to proceed. I'm thinking that I need to somehow add a
    checkbox_checke r() and a checkbox_checke r(2) or something like this.

    I've looked at the "For Dummies" book on JavaScript, and my Beginning
    JavaScript Book as well as Google'd. Funny thing is though you have to have
    enough "knowledge" of JavaScript to know what to look for.

    Please help,
    Thank

    ==== This works like I want it to/ but I have to have one Two Categories,
    this is just one of two.------

    <html>
    <title>Online Class Advisor</title>
    <body>
    <h1>Online Class Advisor</h1>
    <p>The Online Class Advisor will help yout determines what
    classes,confere nces, or books you should consider purchasing based upon
    responses to the following questions. Based upon your selection the Online
    Class Advisor will make recommendations on HSL classes, conferences and
    books.</p>
    <h2>Questions regarding Dreams.</h2>
    <script Language="JavaS cript">

    function checkbox_checke r()
    {
    var checkbox_choice s = 0;
    for (counter = 0; counter < checkbox_form.c heckbox.length; counter++)
    {

    // If a checkbox has been selected it will return true
    // (If not it will return false)
    if (checkbox_form. checkbox[counter].checked)
    { checkbox_choice s = checkbox_choice s + 1; }

    }


    if (checkbox_choic es > 3 )
    {
    // If more than three selections made display
    document.write( "<h3>Based upon your selections the Online Advisor recommends
    the following</h3>");
    document.write( "<br>");
    document.write( "<h4>RECOMMENDE D CLASSES:</h4>")
    document.write( "1. 101 - Hearing the Lost Art.");
    document.write( "<br>");
    document.write( "2. 201 - Understanding your Dreams.");
    document.write( "<br>")
    document.write( "<h4>RECOMMENDE D READING:</h4>")
    document.write( "1. Does my bed hold Dreams by Daniel James")
    document.write( "<br>");
    document.write( "2. Dreams - The Cellular Level of Understanding - Stephen
    Christopher.");
    document.write( "<br>");
    document.write( "<h4>RECOMMENDE D CONFERENCES:</h4>")
    document.write( "Understand ing the Dreams you Dream Symposium - June 12
    Reunion Tower")
    document.write( "<br>");
    document.write( "20th Annual Conference - The Study of Dreams - August 15
    Irving Stadium.");
    document.write( "<br>");
    document.write( "For Detailed Description of Results click
    here".link("#.h tm"))
    document.write( "<br>");
    return (false);
    }


    if (checkbox_choic es < 3 )
    {

    document.write( "<h3>In order to recieve a recommendation, you must make at
    least 3 selections!</h3>")
    return (false);
    }

    // If three are selected write
    document.write( "Based upon your selections the Online Advisor recommends the
    following");
    document.write( "<br>");
    document.write( "<h4>RECOMMENDE D CLASSES:</h4>")
    document.write( "1. 101 - Hearing the Lost Art.");
    document.write( "<br>");
    document.write( "2. 201 - Understanding your Dreams.");
    document.write( "<br>");
    document.write( "<h4>RECOMMENDE D READING:</h4>")
    document.write( "1. Does my bed hold Dreams by Daniel James")
    document.write( "<br>");
    document.write( "2. Dreams - The Cellular Level of Understanding - Stephen
    Christopher.");
    document.write( "<br>");
    document.write( "For Detailed Description of Results click
    here".link("#.h tm"))
    document.write( "<br>");
    return (true);
    }

    -->
    </script>


    <form method="get" action="#"
    onsubmit="retur n checkbox_checke r()" name="checkbox_ form">
    <input type="checkbox" value="I am curious if dreams have any meaning."
    name="checkbox" > I am curious if dreams have any meaning.<br>
    <input type="checkbox" value="I dream often." name="checkbox" >I dream
    often.<br>
    <input type="checkbox" value="My dreams are in color." name="checkbox" >My
    dreams are in color.<br>
    <input type="checkbox" value="I remember and write down my dreams. "
    name="checkbox" >I remember and write down my dreams. <br>
    <input type="checkbox" value="I have a recurring dream." name="checkbox" >I
    have a recurring dream.<br>
    <input type="submit" value="Submit">
    </form>

    </body>
    </html>



  • Evertjan.

    #2
    Re: Two Forms One HTMarriage

    Rich wrote on 01 mei 2005 in comp.lang.javas cript:
    [color=blue]
    > I've been trying to teach myself JavaScript via a book and a number of
    > JavaScript Tutorials Online. I have more understanding of what I am
    > doing, although definetly not has much as what I have read on this
    > newsgroup.
    >[/color]

    The problem with your code is, that you resubmit the page,
    indeed necessary when using document.write( ),
    but try to count the checkboxes without recuperating
    the submitted form values.

    Also there are some code inconsistencies , and spelling errors.
    The script should be in the <head> section.

    The below code does not really "submit" at all and so is quicker:

    =============== =============== =============== ===============

    <html>
    <head>
    <title>Online Class Advisor</title>
    <script type="text/JavaScript">

    function doit(){

    var ccount = 0;
    var cbf = document.getEle mentById('cbf') ;
    var answer = document.getEle mentById('answe r');
    var count = document.getEle mentById('count ');

    for (var c = 0; c < cbf.checkbox.le ngth; c++)
    if (cbf.checkbox[c].checked)
    ccount++;

    if (ccount>3) answer.innerHTM L = tmorethan3
    else if (ccount<3) answer.innerHTM L = tlessthan3
    else answer.innerHTM L = t3;

    count.innerHTML = '('+ccount+')'

    return false;
    }

    tmorethan3 =
    '<h3>Based upon your selections the'+
    'Online Advisor recommends the following</h3><br>'+
    '<h4>RECOMMENDE D CLASSES:</h4>'+
    '1. 101 - Hearing the Lost Art.<br>'+
    '2. 201 - Understanding your Dreams.<br>'+
    '<h4>RECOMMENDE D READING:</h4>'+
    '1. Does my bed hold Dreams by Daniel James<br>'+
    'For Detailed Description of Results click '+
    '<a href="">here</a><br><br>'+
    '2. Dreams - The Cellular Level of Understanding'+
    '- Stephen Christopher.<br >'+
    '<h4>RECOMMENDE D CONFERENCES:</h4>'+
    'Understanding the Dreams you Dream Symposium'+
    '- June 12 Reunion Tower<br>'+
    '20th Annual Conference - The Study of Dreams'+
    '- August 15 Irving Stadium.<br>'+
    'For Detailed Description of Results click '+
    '<a href="">here</a><br>';

    tlessthan3 =
    '<h3>In order to receive a recommendation, '+
    'you must make at least 3 selections!</h3>';

    t3 =
    '<h3>Based upon your selections the'+
    'Online Advisor recommends the following</h3><br>'+
    '<h4>RECOMMENDE D CLASSES:</h4>'+
    '1. 101 - Hearing the Lost Art.<br>'+
    '2. 201 - Understanding your Dreams.<br>'+
    '<h4>RECOMMENDE D READING:</h4>'+
    '1. Does my bed hold Dreams by Daniel James<br>'+
    '2. Dreams - The Cellular Level of Understanding'+
    '- Stephen Christopher.<br >'+
    'For Detailed Description of Results click '+
    '<a href="">here</a><br>';

    </script>


    </head>
    <body>
    <h1>Online Class Advisor</h1>
    <p>The Online Class Advisor will help you determine what
    classes,confere nces, or books you should consider purchasing
    based upon responses to the following questions.
    Based upon your selection the Online Class Advisor will make
    recommendations on HSL classes, conferences and books.</p>
    <h2>Questions regarding Dreams.</h2>

    <form
    onsubmit="retur n doit();" id="cbf">
    <input type="checkbox" name="checkbox" >
    I am curious if dreams have any meaning.<br>
    <input type="checkbox" name="checkbox" >
    I dream often.<br>
    <input type="checkbox" name="checkbox" >
    My dreams are in color.<br>
    <input type="checkbox" name="checkbox" >
    I remember and write down my dreams. <br>
    <input type="checkbox" name="checkbox" >I
    have a recurring dream.<br>
    <input type="submit" value="Submit">
    </form>

    Answer: <span id=count></span><br>

    <div id='answer'>
    No answer as yet,<br>
    Please submit the above.
    </div>


    </body>
    </html>


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)

    Comment

    Working...