-2

クイズを作ろうとしています。各回答には、異なる値を持つ複数のラジオボタンがあります。ユーザーがボタンをクリックすると、関数 'computeForm()' はチェックされたラジオボタンのすべての値の合計を作成し、ブラウザを正しい Web ページにリダイレクトします。

この時点では、ボタンをクリックしても何も起こりません。

html:

<form METHOD=POST>
                    <p>My favourite TV show in this list is:<br/></p>
                    <input type="radio" name="answer1" value="0"/>The Simpsons<br/>
                    <input type="radio" name="answer1" value="1"/>The Big Bang Theory<br/>
                    <input type="radio" name="answer1" value="2"/>Naruto<br/>
                    <input type="radio" name="answer1" value="3"/>Spartacus<br/>
                    <input type="radio" name="answer1" value="4"/>Game Of Thrones<br/>
                    <input type="radio" name="answer1" value="5"/>Arrow<br/>
                    <input type="radio" name="answer1" value="6"/>The Walking dead<br/>
                    <input type="radio" name="answer1" value="7"/>Mad Men<br/>
                    <input type="radio" name="answer1" value="8"/>Documentary<br/>
                    </br>
                    <p>Choose a synonym for 'graphic novel'<br/></p>
                    <input type="radio" name="answer2" value="1"/>Comicbook<br/>
                    <input type="radio" name="answer2" value="2"/>tome<br>
                    <input type="radio" name="answer2" value="9"/>Report<br/>
                    <input type="radio" name="answer2" value="0"/>Funny pages<br/>
                    <input type="radio" name="answer2" value="4"/>Tale of wonder<br/>
                    <input type="radio" name="answer2" value="5"/>Adventures<br/>
                    <input type="radio" name="answer2" value="3"/>scenario<br/>
                    <input type="radio" name="answer2" value="7"/>book<br/>
                    </br>
                    <p>My favourite actor in this list:<br></p>
                    <input type="radio" name="answer3" value="4"/>Elijah Wood</br>
                    <input type="radio" name="answer3" value="5"/>Christian Bale</br>
                    <input type="radio" name="answer3" value="1"/>Danny DeVito</br>
                    <input type="radio" name="answer3" value="2"/>Junko Takeuchi</br>
                    <input type="radio" name="answer3" value="6"/>Norman Reedus</br>
                    <input type="radio" name="answer3" value="7.5"/>Daniel Day-Lewis</br>
                    <input type="radio" name="answer3" value="0"/>Homer Simpson</br>
                    <input type="radio" name="answer3" value="3"/>Russel Crowe</br>
                    </br>
                    <p>For me, a good antagonist is:<br></p>
                    <input type="radio" name="answer4" value="0"/>a Laughing stock</br>
                    <input type="radio" name="answer4" value="4"/>a dark creature</br>
                    <input type="radio" name="answer4" value="5"/>a supervillain</br>
                    <input type="radio" name="answer4" value="1"/>a funny enemy</br>
                    <input type="radio" name="answer4" value="3"/>a personal enemy</br>
                    <input type="radio" name="answer4" value="7"/>defined by the protagonist's actions</br>
                    <input type="radio" name="answer4" value="9"/>a real person</br>
                    <input type="radio" name="answer4" value="2"/>a former friend</br>
                    <input type="radio" name="answer4" value="6"/>an undead</br>
                    </br>
                    <p>The drawingstyle i like most:<br></p>
                    <input type="radio" name="answer5" value="3"/>Modern</br>
                    <input type="radio" name="answer5" value="7.5"/>Realistic</br>
                    <input type="radio" name="answer5" value="4"/>Detailed</br>
                    <input type="radio" name="answer5" value="2"/>Manga</br>
                    <input type="radio" name="answer5" value="0.5"/>Caricaturist</br>
                    <input type="radio" name="answer5" value="6"/>Dark</br>
                    <input type="radio" name="answer5" value="5"/>American</br>
                    </br>
                    <p>My favourite visual artist:<br></p>
                    <input type="radio" name="answer6" value="1"/>Matt Groening</br>
                    <input type="radio" name="answer6" value="2"/>Akira Toriyama</br>
                    <input type="radio" name="answer6" value="5"/>Jack Kirby</br>
                    <input type="radio" name="answer6" value="6"/>Charlie Adlard</br>
                    <input type="radio" name="answer6" value="7"/>Osamu Tezuka</br>
                    <input type="radio" name="answer6" value="8"/>Joe Sacco</br>
                    <input type="radio" name="answer6" value="3"/>Grzegorz Rosiński</br>
                    <input type="radio" name="answer6" value="4"/>Hans Rudolf Giger</br>
                    <input type="radio" name="answer6" value="0"/>don't have one</br>
                    </br>
                    <p>From this list, my favourite graphic novel is:<br></p>
                    <input type="radio" name="answer7" value="0"/>Spike &amp; Suzy</br>
                    <input type="radio" name="answer7" value="1"/>Game Over</br>
                    <input type="radio" name="answer7" value="6"/>Crossed</br>
                    <input type="radio" name="answer7" value="9"/>Maus</br>
                    <input type="radio" name="answer7" value="2"/>Death Note</br>
                    <input type="radio" name="answer7" value="3"/>300</br>
                    <input type="radio" name="answer7" value="4"/>The Cninkel</br>
                    <input type="radio" name="answer7" value="5"/>Batman: The Dark Knight</br>
                    <input type="radio" name="answer7" value="7"/>Transmetropolitan</br>
                    <input type="button" value="Take me away" onclick="computeForm(this.form);" /><br><br>
                </form>

脚本:

<script type="text/javascript" language="javascript">

function getValue(name){
var s =0;
var o = document.getElementsByName(name);
for (var n = 0; n < o.length; n++){
    if (o.item(n).checked){
        s = parseInt(o.item(n).value);
    }
}

return s;
}


function computeForm(form) {
var total;

var answer1 = parseInt(getValue('answer1'));
var answer2 = parseInt(getValue('answer2'));
var answer3 = parseInt(getValue('answer3'));
var answer4 = parseInt(getValue('answer4'));
var answer5 = parseInt(getValue('answer5'));
var answer6 = parseInt(getValue('answer6'));
var answer7 = parseInt(getValue('answer7'));

total = (answer1 + answer2 + answer3 + answer4 + answer5 + answer6 + answer7);

if (total=0){ window.location="http://www.cartoons-cinema.be/" }
else if (total >0 && total<=7){ window.location="http://en.wikipedia.org/wiki/Sitcom" }
else if (total >7 && total<=14){ window.location="http://en.wikipedia.org/wiki/Anime" }
else if (total >14 && total<=21){ window.location="http://www.asadventure.com/benl/index.cfm" }
else if (total >28 && total<=35){ window.location="https://en.wikipedia.org/wiki/Fantasy" }
else if (total >35 && total<=42){ window.location="http://www.urbandictionary.com/define.php?term=supes" }
else if (total >42 && total<=49){ window.location="http://www.goodreads.com/shelf/show/post-apocalyptic?auto_login_attempted=true" }
else if (total > 49){ window.location="https://en.wikipedia.org/wiki/Non-fiction" }
}
</script>
4

1 に答える 1

1

これはあなたのために働くjsfiddleです。

あなたのイニシャルifに「=」がありませんでした

if(total==0)
于 2013-05-22T19:44:05.867 に答える