$('input[name = bbs]').on('click',function(e)から下の処理について処理できない箇所があるので添削していただきたいです
⓵
$('input[name = bbs]').on('click',function(e)の箇所は、radioのID属性をpropし、各radioが押される度にsubmitボタンの名前が変化する処理を行いたくて、propしたidをID属性sendに代入してchangeというようにしてみても処理されません
何故でしょうか
⓶
$('input[name = chkid[]]').on('click',function()の箇所は、各radioが押された時にtrueかfalseか判別し、trueだったらchkid[]をdisabledするよう処理を行いたくて、変数myidはradioのID属性をpropしたものを定義、sendに変数sendlistと変数myidをvalueに含めて、変数sendlistと変数myidの判別処理をpropしchkid[]に代入するようにしてみても処理されません
何故でしょうか
<script> $(document).ready(function() { $('form').on('submit',function() {//フォーム入力時の条件分岐 if ($('#r1').prop('checked')) { with($('#name')) { if (val().length >= 10) { window.alert("ERROR1"); return false; } if (val() === "") { window.alert("ERROR2"); return false; } } with($('#comment')) { if (val().length >= 300) { window.alert("ERROR3"); return false; } if (val() === "") { window.alert("ERROR4"); return false; } } } if ($('#r2').prop('checked') || $('#r3').prop('checked')) { if ($('[name = "chkid[]"]:checked').length == 0) { window.alert("ERROR5"); return false; } } return true; }); $('input[name = bbs]').on('click',function(e) {//「bbs」が押された時にsebmitボタンの名前が変化 change($('#send').prop('id')); }); $('input[name = chkid[]]').on('click',function() {//「bbs」が押された時にbbsの処理によっては投稿はtrue、更新・削除はfalseでchkid[]がdisabledか否か var myid = $('input[name = bbs]').prop('id') var sendlist = { "r1":{"text":"投稿",checkflg:true}, "r2":{"text":"更新",checkflg:false}, "r3":{"text":"削除",checkflg:false}, }; $('#send').val(sendlist[myid].text); $('[name = "chkid[]"]').prop('disabled',sendlist[myid].checkflg); }); }); </script> </head> <body> <form method="post" action=""> <table> <tr> <td> 名前:<input type="text" name="name" id="name"> 内容:<textarea name="comment" cols="30" rows="3" id="comment"></textarea> <input type="radio" name="bbs" id="r1" value="post">投稿 <input type="radio" name="bbs" id="r2" value="update">更新 <input type="radio" name="bbs" id="r3" value="delete">削除 <input type="submit" id="send"> </td> </tr> </table>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。