View Single Post
Old 01-26-2014, 04:01 AM   #1
BertrandThibaut
Junior Member
BertrandThibaut began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jan 2014
Device: none
Create a javascript quizz for Epub3 in Sigil

Hello, I'm trying to add a quizz form in javascript to an ebook created with Sigil (0.6.2).

Here is the code I used

Quote:
<head>
<title></title>
<link href="../Styles/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">




//<![CDATA[
function calcul()
{
nombreDeQuestion=10;
nom=new Array();
nomLength=new Array();
point=0;
for(n=0;n<=(nombreDeQuestion-1);n++)
{
nom[n]=document.getElementsByName("choix_rep_"+n);
nomLength[n]=nom[n].length;
for(q=0;q<=(nomLength[n]-1);q++)
{
if(nom[n][q].checked==true)
{point=point+eval(nom[n][q].value);}
else
{point=point;}

}
}
document.form_qz.txtNb.value=point;
}

//]]>
</script>
</head>


Quote:
<div>
<form id="form_qz">
<p>Le colvert est :<br />
<input type="radio" name="choix_rep_0" value="1" />un canard<br />
<input type="radio" name="choix_rep_0" value="0" />un coq<br />
<input type="radio" name="choix_rep_0" value="0" />un perroquet</p>

<p>Le petit-gris est:<br />
<input type="radio" name="choix_rep_1" value="0" />un rat<br />
<input type="radio" name="choix_rep_1" value="0" />un chat<br />
<input type="radio" name="choix_rep_1" value="1" />un escargot</p>

<p>Quel est le nom du poisson surnommé le "cheval de mer"?<br />
<input type="radio" name="choix_rep_2" value="0" />Le dauphin<br />
<input type="radio" name="choix_rep_2" value="1" />L'hippocampe<br />
<input type="radio" name="choix_rep_2" value="0" />L'espadon</p>

<p>Quelle est la capitale de l'Italie?<br />
<input type="radio" name="choix_rep_3" value="0" />Venise<br />
<input type="radio" name="choix_rep_3" value="0" />Milan<br />
<input type="radio" name="choix_rep_3" value="1" />Rome</p>

<p>Quelle est la capitale de l'Espagne?<br />
<input type="radio" name="choix_rep_4" value="1" />Madrid<br />
<input type="radio" name="choix_rep_4" value="0" />Tolède<br />
<input type="radio" name="choix_rep_4" value="0" />Barcelone</p>

<p>Quelle est la capitale de la Chine?<br />
<input type="radio" name="choix_rep_5" value="1" />Pékin<br />
<input type="radio" name="choix_rep_5" value="0" />Hongkong<br />
<input type="radio" name="choix_rep_5" value="0" />Shanghaï</p>

<p>Quelle pâtisserie mange-t-on le plus souvent à Noël en France?<br />
<input type="radio" name="choix_rep_6" value="0" />La galette des rois<br />
<input type="radio" name="choix_rep_6" value="1" />La bûche de Noël<br />
<input type="radio" name="choix_rep_6" value="0" />La religieuse</p>

<p>Est-ce que l’été est suivi immédiatement par le printemps?<br />
<input type="radio" name="choix_rep_7" value="1" />Non<br />
<input type="radio" name="choix_rep_7" value="0" />Oui</p>

<p>Est-ce que le sel a un goût sucré?<br />
<input type="radio" name="choix_rep_8" value="1" />Non<br />
<input type="radio" name="choix_rep_8" value="0" />Oui</p>

<p>Les pommes sont-elles toujours vertes?<br />
<input type="radio" name="choix_rep_9" value="0" />Oui<br />
<input type="radio" name="choix_rep_9" value="1" />Non</p>

<p>le nombre de réponses correctes est : <input type="button" name="btnAfficher" value="afficher le reslultat" onclick="calcul();" /><br />
<input type="text" name="txtNb" id="resultat" /></p>
</form>
</div>
The form is well displayed in my epub file but...

- When I choose an answer for the questions 1 or 2, clicking on the radio button send me to my cover page.
- I can choose an answer for question 3 to 10 but when I click on the button btnAfficher to get my results, nohtings happens.

I test my epub file with Firefox 26.0

Any ideas how to solve it ?
BertrandThibaut is offline   Reply With Quote