Click here to Skip to main content
15,749,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am making a questionaire for my school project.
I have a "fill-out-form" which is a place for people to fill their data such as name, age, etc.
Then, I have "questionaire form" named "music.html" and "math.html".
If music.html has been answered, then it will go to math.html .
If both of the questionaire forms have been answered, it will show the result like:

Name : John
Age : 20
Music score : 5
Math score : 2

At last, it will store the data (name, age, music score and math score) to database MySql.
How can I do this? Thanks in advance.

<form name="myform" method="post" action="music.html">
    Username	: <input name="username" type="text"> <br>
    Age	        : <input name="age" type="text"> <br>
<input name="Button" type="button" value="SUBMIT">

Here's music.html looks like:
<script type="text/javascript" src="../js/script.js"></script>

<form name="myform" method="post"
 önSubmit="return validateRadio()" action="math.html">

<table class="tftable" border="1">
<tr><th><div align="center" class="tftable th">Questions</div></th><th colspan="2"><div align="center">Answer</div></th>
  <td>I like to dance</td>

  <input name="bm1" type="radio" value="1" />

  <input name="bm1" type="radio" value="2" />
  <td>I like to play sports such as baseball, soccer, hockey, or football </td>
  <input name="bm2" type="radio" value="1" />
  <input name="bm2" type="radio" value="2" />
  No </label>

My math.html looks same like this just different on the questions.
I have put javascript to count how many "yes" answer are there. If there're 4 yes then
music score : 4
I have put javascript to count the "yes" answer

function validateRadio()
// get all the inputs type
var inputs = myform.elements;
var radios = [];

// find the radio type
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'radio') {
var countChecked = 0;
for (var j = 0; j < radios.length; j++) {
if (radios[j].checked) {
//count number of radio button with value=1
var answeramount = 0;
for (var k = 0; k < radios.length; k++){
if(radios[k].checked && radios[k].value==1){
if (countChecked != radios.length / 2){
alert("All questions must be answered.");
return false; // abort submit
} else {
return true; // proceed to submit
Updated 19-Mar-14 6:31am

1 solution

This is not going to work, only html and javascript, it goes no where.
You have to include php code in order to pass values from page to page, other things like the setting up of an Apache server, and mysql server too.
To accomplish this project, you have to start learning PHP+MySQL[^]
When you encounter problems subsequently in your php or mysql coding, always ask Google first, then visit CP to post questions related to specific issues.
Share this answer
monsterchub 19-Mar-14 14:53pm    
In PHP, what should i use to pass value?
session or is there something else?
or maybe i can store the value in hidden form and pass the value to PHP?
Peter Leow 19-Mar-14 23:03pm    
Yes, you are almost there: Specifically, pass form data using either get or post method and place them in some hidden fields in the receiving page. See on get and post methods.
monsterchub 20-Mar-14 12:20pm    
Great thx Peter Leow

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900