iT邦幫忙

0

html checkbox相同名稱傳值錯誤!!!

Dear 各位IT前輩~
小弟有個問題要請教,就是上網GOOGLE相同名稱傳值到下一頁,還是會有錯誤~
是Value值還是哪裡設錯...
在html的兩個地方
1.
2.
傳到下一頁1.都會顯示正確,則2.只要打勾就會顯示0,不會顯示1...連1.都會顯示有問題...
麻煩大大解惑ˊˋ

javascript部分

<script language="javascript" type="text/javascript">
    function Delete() 
    {
        if (confirm("您是否確定刪除??"))
        {
        	var query_string = 'http://www.diva.com.tw/backend/zh-tw/auth/deleteAdmin';	
	        document.getElementById( "update_form" ).action = query_string;	
	        document.getElementById( "update_form" ).submit();     
        }
    }
	
	function Launch() 
    {
        	var query_string = 'test.php';	
	        document.getElementById( "update_form" ).action = query_string;	
	        document.getElementById( "update_form" ).submit();     
    }
	
	
	function Launch1() 
    {
		if(update_form.jobnumber.value == "") 
        {
                        alert("未輸入工號。");
        }
		else
		{	
	
        	var query_string = 'permissions1_finish.php';	
	        document.getElementById( "update_form" ).action = query_string;	
	        document.getElementById( "update_form" ).submit();     
		}
    }
	
	
	function Launch2() 
    {
		if(update_form.jobnumber.value == "") 
        {
                        alert("未輸入工號。");
        }
		else
		{			
        	var query_string = 'permissions1_finish.php';	
	        document.getElementById( "update_form" ).action = query_string;	
	        document.getElementById( "update_form" ).submit(); 
        }			
    }
	

</script>

html部分

<form action="" id="update_form" method="post">
    <div class="contentForm">

        <div class="list">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
              <tr>
                <th width="1.2%" >帳號</th> 
                <th width="1.3%" >SAP損益表</th>            
                <th width="1.0%" >TEST1_PAGE</th>
				<th width="1.3%" ></th>
				<th width="1.2%" ></th>
				<th width="1.2%" ></th>
				<th width="1.2%" ></th>
                <th width="1.2%" >啟用</th>
                <!--<th width="1.2%" >刪除</th>-->
              </tr>
            </table>
			
			<BR>
			
			<table width="100%" border="0" cellspacing="0" cellpadding="0" >
               <tr class="">
			    <td width="12%" >
				<input type="text" name="jobnumber" value="" size="14" style="width:95px;text-transform:capitalize;" maxlength="5" placeholder="請輸入工號"/>
				</td> 
				
                <td width="12%" >
				<input name="launch2[]" id="launch1" value="0" type="checkbox" >
                <!--<input type="hidden" name="launch_org[]" value="1" />-->
				</td>      
				
                <td width="18%" >
				<input name="launch2[]" id="launch2" value="0" type="checkbox" >
                <!--<input type="hidden" name="launch_org[]" value="1" />-->
				
				</td>
				<td width="15%" ></td>
				<td width="16%" ></td>
				<td width="16%" ></td>
			   
  
                <td width="11.4%">
                	<input name="launch" id="launch" value="" type="checkbox" >
                </td>
				
                <!--<td width="12%"><input name="del[]" id="del" value="1" type="checkbox" >-->
				</td>
				
              </tr>
			  
			   </table><BR>
			   
			   
                
              
			  
			  
			  
			  
			  <table width="100%" border="0" cellspacing="0" cellpadding="0" >
              <tr>
              	
				<td width="12%" >
				
              	<td width="12%" >
				<!--
                	<input value="全選" type="button" class="btn" onclick="SelectAll( 'launch1' )"/><br />
                	<input value="反向選擇" type="button" class="btn" onclick="ReverseSelect( 'launch1' )" /><br />
                    <input value="確認" type="button" class="btn" onclick="Launch1()"/>
					
			    -->
                </td>
				
				<td width="18%" >
                	<input value="全選" type="button" class="btn" onclick="SelectAll( 'launch2[]' )"/><br />
                	<input value="反向選擇" type="button" class="btn" onclick="ReverseSelect( 'launch2[]' )" /><br />
                    <input value="確認" type="button" class="btn" onclick="Launch2()"/>
                </td >
				
				
				<td width="15%" ></td>
				<td width="16%" ></td>
				<td width="16%" ></td>
				
				
				<td width="50%" >
                	<input value="全選" type="button" class="btn" onclick="SelectAll( 'launch' )"/><br />
                	<input value="反向選擇" type="button" class="btn" onclick="ReverseSelect( 'launch' )" /><br />
                    <input value="確認" type="button" class="btn" onclick="Launch()"/>
                </td>
				
				
				<!--
                <td>
                	<input value="全選" type="button" class="btn" onclick="SelectAll( 'del[]' )"/><br />
                	<input value="反向選擇" type="button" class="btn" onclick="ReverseSelect( 'del[]' )" /><br />
                    <input value="確認" type="button" class="btn" onclick="Delete()"/>
                </td>
				-->
              </tr>
            </table>
           
        </div>    
    </div>
</form>        
小哈 iT邦新手 4 級 ‧ 2017-03-21 14:36:29 檢舉
補充
1.<input name="launch2[]" id="launch1" value="0" type="checkbox" >
2.<input name="launch2[]" id="launch1" value="0" type="checkbox" >
小哈 iT邦新手 4 級 ‧ 2017-03-21 14:37:26 檢舉
第二頁印出不正常
<?
$launch1_d = (isset($_POST['launch2'][0])) ? 1 : 0;
$launch2_d = (isset($_POST['launch2'][1])) ? 1 : 0;

echo $launch1_d;
echo $launch2_d;
?>
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
wonton
iT邦高手 6 級 ‧ 2017-03-21 15:15:39

只有 checkbox 被選取時,才會傳值。所以如果你有勾選兩個 checkbox,$_POST['launch2'][0] 和 $_POST['launch2'][1] 才會有值;只有勾一個 checkbox 的話,不管勾選第一個還是第二個,那就都只有 $_POST['launch2'][0] 有值而已。

因此你應該是調整 value 內容,然後再依據獲取的 value 值,知道是哪一個 checkebox 被勾選。像現在這樣你的 value 都為 0,第二頁就會不知道到底是哪一個被勾選了...

小哈 iT邦新手 4 級 ‧ 2017-03-21 16:18:49 檢舉

Dear wonton 大大~
我也有把value改成2 不過還是一樣會影響...

而且$_POST['launch2'][0] 有沒有打勾都正確
不過換成$_POST['launch2'][1]打勾1沒打勾,還是會發生問題...
/images/emoticon/emoticon02.gif

wonton iT邦高手 6 級 ‧ 2017-03-21 17:36:25 檢舉

建議你第二頁加入這一段,看看 output 的值,是否如您想像。

echo "<pre>"; print_r($_POST); echo "</pre>";

有時候除錯,把內容值顯示出來會比較容易知道錯誤。

我要發表回答

立即登入回答