Two Forms One HTMarriage

R

Rich

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_checker() and a checkbox_checker(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,conferences, 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="JavaScript">

function checkbox_checker()
{
var checkbox_choices = 0;
for (counter = 0; counter < checkbox_form.checkbox.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_choices = checkbox_choices + 1; }

}


if (checkbox_choices > 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>RECOMMENDED 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>RECOMMENDED 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>RECOMMENDED CONFERENCES:</h4>")
document.write("Understanding 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("#.htm"))
document.write("<br>");
return (false);
}


if (checkbox_choices < 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>RECOMMENDED 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>RECOMMENDED 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("#.htm"))
document.write("<br>");
return (true);
}

-->
</script>


<form method="get" action="#"
onsubmit="return checkbox_checker()" 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>
 
E

Evertjan.

Rich wrote on 01 mei 2005 in comp.lang.javascript:
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.

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.getElementById('cbf');
var answer = document.getElementById('answer');
var count = document.getElementById('count');

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

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

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

return false;
}

tmorethan3 =
'<h3>Based upon your selections the'+
'Online Advisor recommends the following</h3><br>'+
'<h4>RECOMMENDED CLASSES:</h4>'+
'1. 101 - Hearing the Lost Art.<br>'+
'2. 201 - Understanding your Dreams.<br>'+
'<h4>RECOMMENDED 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>RECOMMENDED 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>RECOMMENDED CLASSES:</h4>'+
'1. 101 - Hearing the Lost Art.<br>'+
'2. 201 - Understanding your Dreams.<br>'+
'<h4>RECOMMENDED 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,conferences, 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="return 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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top