プロが教える店舗&オフィスのセキュリティ対策術

よくある○○度チェックみたいなものを作っているのですが、
項目が10個程あって、
「チェックが0個~4個のあなたは、△△△!!」
「チェックが5個~7個のあなたは、◇◇◇!!」
「チェックが8個~10個のあなたは、◎◎◎!!」
という流れなのです。

で、その3パターンの結果ごとに異なる
HTMLをポップアップウィンドウで表示させたいのです。
たいていは次のページに結果を表示させるパターンですが、ここをポップアップ表示させたいのです。
しかも3つそれぞれのHTMLに。

<script language="JavaScript">
function myCheck(){
myCnt=0 // チェックした数
for (i=0; i<document.myForm.length-1; i++){
// チェックボックスの数分ループ
if (document.myForm.elements[i].checked == true){
// チェックはオンか?
myCnt++ // チェック数 加算
}
}
if ( myCnt <= 3 ){ // チェックは 無し(ゼロ)
myUrl = "check_1.html";
}
else if ( myCnt <= 5 ){ // チェックは 1以上6以下
myUrl = "check_2.html";
}
else if ( myCnt > 5 ){ // チェックは 1以上6以下
myUrl = "check_3.html";
}
funMsgUrl(myUrl)
}
function funMsgUrl(url){
location.href = url
}
</script>

 ・
 ・
 ・

<form name="myForm">
<input name="checkbox1" type="checkbox">項目<br>
<input name="checkbox2" type="checkbox">項目<br>
<input name="checkbox3" type="checkbox">項目<br>
 ・
 ・
 ・
<input name="checkbox9" type="checkbox">項目<br>
<input name="checkbox10" type="checkbox">項目<br>
</form>

<input type="button" onClick="myCheck(); return false;" value="チェック">

すみませんが、助言をお願いいたします。

A 回答 (2件)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html><head><title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function myCheck(){
myCnt=0 // チェックした数
for (i=0; i<document.myForm.length-1; i++){
// チェックボックスの数分ループ
if (document.myForm.elements[i].checked == true){
// チェックはオンか?
myCnt++ // チェック数 加算
}}
// チェックは 無し(ゼロ)
if(myCnt==0)window.open('check_1.htm','sub','width=300,height=300');
// チェックは 1以上6以下
if(myCnt>0&&myCnt<7)window.open('check_2.htm','sub','width=300,height=300');
//チェックは 7以上
if(myCnt>=7)window.open('check_3.htm','sub','width=300,height=300');
}
</script>
</head><body>
<form name="myForm">
<input name="checkbox1" type="checkbox">項目<br>
<input name="checkbox2" type="checkbox">項目<br>
<input name="checkbox3" type="checkbox">項目<br>
<input name="checkbox4" type="checkbox">項目<br>
<input name="checkbox5" type="checkbox">項目<br>
<input name="checkbox6" type="checkbox">項目<br>
<input name="checkbox7" type="checkbox">項目<br>
<input name="checkbox8" type="checkbox">項目<br>
<input name="checkbox9" type="checkbox">項目<br>
<input name="checkbox10" type="checkbox">項目<br>
<input type="button" onClick="myCheck()" value="チェック">
</form>
</body>
</html>
    • good
    • 0

function funMsgUrl(url){


location.href = url
}

function funMsgUrl(url){
window.open(url);
}
にする

参考URL:http://www.htmq.com/js/window_open.shtml
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!