iT邦幫忙

0

jsp checkbox確認後自動更新text的值

想請教各位大大
我有一個表格,checkbox,value(預設0),item
我希望使用者checkbox按下去後,value自動重0變1
但一值變不過去....
想請教各位到底是錯在哪?


<div class="container">
  <table ><tbody id="myTable">
   <%
          String sql = "select * from send"; 
            pstmt = conn.prepareStatement(sql);  
             ResultSet rs = pstmt.executeQuery(); 
             pstmt.setQueryTimeout(60);
	         while(rs.next()){ 
                String name = rs.getString("name");
                  String c_id = rs.getString("c_id"); 
      out.print("<tr><td>"+"<input type='checkbox' name='a' value="+c_id+" onclick='testfun( this ,"+c_id+")'>"+"</td>" + "<td><input type='text' id='"+c_id+"' name='count' value=0 SIZE=5></td><td>"+name+"</td></tr> ");
     }
	                rs.close(); 
 %>
    </tbody>
  </table>
  </form>
</div>
<script type="text/javascript">
function testfun(element, c_id) {
  var x = document.getElementById(c_id);
 window.alert(c_id);
  if (element.checked) {
    x.value =1;
  } else {
    x.value = 0;
  }
}
</script>
   

謝謝大家

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
dragonH
iT邦超人 5 級 ‧ 2020-03-27 16:03:12
最佳解答

不知道

不過我會把 element c_id x

都印出來看

codepen

看更多先前的回應...收起先前的回應...

問題應該是他設兩個一樣的 id XD
看錯了/images/emoticon/emoticon48.gif

joker iT邦新手 5 級 ‧ 2020-03-27 16:08:27 檢舉

有,解決了,謝謝

咖咖拉 iT邦好手 1 級 ‧ 2020-03-27 16:10:37 檢舉
value="+c_id+" 
value='"+c_id+"'

請問這2個寫法再JSP有差別嗎?
/images/emoticon/emoticon16.gif

dragonH iT邦超人 5 級 ‧ 2020-03-27 16:11:45 檢舉

就組 string 而已吧

不過很懶得看XD

/images/emoticon/emoticon48.gif

我要發表回答

立即登入回答