2012-03-04 7 views
-1

4つのドロップダウンリストがあります。各ドロップダウンリストはすべて偽値と真の値を持ちますが、私の目的は、警告メッセージを生成し、値が真であることに基づいて新しいページを開くことです。しかし、このコードをボタンに適用する方法を知りたいので、ボタンがクリックされたときに記述されたアクションは、現時点では何も起こっていないため、発生します。ボタンに機能を適用する方法

<input name="button" type="submit" class="main" id="button" value="Submit" onclick="submit()" /> 


</script> 

<script type="javascript"> 

これは、そのあなたの参考のためにここに置か私のボタンの詳細

<input name="button" type="submit" class="main" id="button" value="Submit" onclick="submit()" /> 

var selectbox = document.getElementById("select_box"); 
var a = selectbox.options[selectbox.selectedIndex].value; 

var selectbox2 = document.getElementById("select_box2"); 
var b = selectbox2.options[selectbox2.selectedIndex].value; 

var selectbox3 = document.getElementById("select_box3"); 
var c = selectbox3.options[selectbox3.selectedIndex].value; 

var selectbox4 = document.getElementById("select_box4"); 
var d = selectbox4.options[selectbox4.selectedIndex].value; 


if (a == "true" && b == "true" && c == "true" && d == "true") 
{ 
alert("Correct you have won press OK for your Reward!") 
document.open("Reward.html"); 
} 
else 
{ 
alert("Not right Please try again!"); 
} 

</script> 

答えて

0

は、このような機能を確認してくださいあなたのonClick値ポイントを作るです:

<input name="button" type="submit" class="main" id="button" value="Submit" onclick="checkValues();"/> 

、実際に機能存在:

function checkValues(){ 
var selectbox = document.getElementById("select_box"); 
var a = selectbox.options[selectbox.selectedIndex].value; 

var selectbox2 = document.getElementById("select_box2"); 
var b = selectbox2.options[selectbox2.selectedIndex].value; 

var selectbox3 = document.getElementById("select_box3"); 
var c = selectbox3.options[selectbox3.selectedIndex].value; 

var selectbox4 = document.getElementById("select_box4"); 
var d = selectbox4.options[selectbox4.selectedIndex].value; 

if (a == "true" && b == "true" && c == "true" && d == "true") 
    { 
     alert("Correct you have won press OK for your Reward!") 
     document.open("Reward.html"); 
    } 
    else 
    { 
     alert("Not right Please try again!"); 
    } 
} 

幸運!

+0

ボタンをクリックしても何も表示されませんが、ボタンのコードは実際にはすべてのif文が何かである必要がありますか? – user1243542

+0

いくつかのalert()文を追加して、問題の内容を確認してください。関数は実際に呼び出されていますか? selectbox変数に値がありますか?また、JavaScriptのエラーログをチェックして何が間違っているのかを確認してください。 – Wesley

関連する問題