いつもお世話になっております。
参考サイト▼
https://teratail.com/questions/91101
参考サイトのベストアンサーをコピペでテストページを作成し、
ラジオボタンを選択すると選択に応じた値を取得してくれます。
ただ取得してくれるのは良いのですが、
ポップアップでは無くて、リンクしてページを移動してほしいんです。
調べて見たのですが、うまくいかず...お力添えお願いしますm(_ _)m
【追記】
丸投げですみません!
コードは以下の内容です。調べたと言っても意味を理解できておらず
コード自体は参考サイトのコピペのまま変わりはありません。汗
<script> document.addEventListener('click',function(e){ var t=e.target; var url={ "1_1":"1.html", "1_2":"2.html", "2_1":"3.html", "2_2":"4.html", } if(t.nodeName=="INPUT" && t.type=="submit" && t.value=="移動"){ var n1=document.querySelector('input[type=radio][name=room]:checked'); var n2=document.querySelector('input[type=radio][name=book]:checked'); if(n1 == null || n2 == null || typeof url[n1.value+"_"+n1.value]=="undefined"){ e.preventDefault(); }else{ alert(url[n1.value+"_"+n2.value]); } } }); </script> <form method="post"> <p> <input type="radio" name="room" value="1">リビング <input type="radio" name="room" value="2">ベッドルーム </p> <p> <input type="radio" name="book" value="1">小説 <input type="radio" name="book" value="2">ビジネス </p> <input type="submit" value="移動"> </form>
euledgeさんに教えて頂いた内容で以下の様にして
リンクをつける事はクリアできました!ありがとうございます!
<script language="JavaScript"> function link() { if ( document.form1.room[0].checked == true && document.form1.book[0].checked == true ) window.location.href =("01.html") if ( document.form1.room[0].checked == true && document.form1.book[1].checked == true ) window.location.href =("02.html") if ( document.form1.room[1].checked == true && document.form1.book[0].checked == true ) window.location.href =("03.html") if ( document.form1.room[1].checked == true && document.form1.book[1].checked == true ) window.location.href =("04.html") } </script> <form name="form1" method="post" target="_blank"> <p> <input type="radio" name="room">リビング <input type="radio" name="room">ベッドルーム </p> <p> <input type="radio" name="book">小説 <input type="radio" name="book">ビジネス </p> <input type="button" value="移動" onclick="link()"> </form>
回答2件
あなたの回答
tips
プレビュー