2013-06-27 44 views
0

中的下拉列表重新加載頁面我的頁面上有一個下拉列表,並在同一頁面上有一個html表格,並且有來自數據庫表格的值。 下拉列表有3個選項。即聯邦,州和地方 我希望當我選擇任何選項時,我的頁面將重新加載到同一頁面上,並更改表中列值,該值在數據庫中設置爲federal_value,state_value和local_value。根據php

<select name="election" id="text" > 
      <option value="federal"> Federal </option> 
      <option value="state"> State </option> 
      <option value="local"> Local </option> 
      </select> 

this is dropdown list code 


    <form name="form1"> 
       <table width="90%" border="0" cellpadding="1" cellspacing="1" bgcolor="#c0c0c0"> 
       <tr> 
        <td width="9%" align="center" bgcolor="#FFFFFF" class="head01"><input type="checkbox" value="1" onClick="$('input[name*=\'selected\']').attr('checked', this.checked);" id="check_all" name="data[Farm][check_all]" > 
        </td> 
        <td width="7%" align="center" bgcolor="#FFFFFF" class="head01">Sr. No. </td> 
        <td width="25%" align="center" bgcolor="#FFFFFF" class="head01">Leader name</td> 
        <td width="13%" align="center" bgcolor="#FFFFFF" class="head01">Facebook Like</td> 
        <td width="11%" align="center" bgcolor="#FFFFFF" class="head01">Twitter Like</td> 
        <td width="10%" align="center" bgcolor="#FFFFFF" class="head01" id="value"> Value</td> 
        <td width="12%" align="center" bgcolor="#FFFFFF" class="head01">View Profile</td> 
        <td width="15%" align="center" bgcolor="#FFFFFF" class="head01">Select PM</td> 
       </tr> 


    <?php 
    $election=$_REQUEST['election']; 
    $result = mysql_query("SELECT * FROM leader_info"); 
    $i=1; 
     while($row = mysql_fetch_assoc($result)) 
      {    
    ?> 
       <tr> 
        <td bgcolor="#FFFFFF" align="center"><input type="hidden" value="0" id="chkids" name="chkid[0]"> 
        <input type="checkbox" id="ChkIds" value="<?php echo $row['leader_id']; ?>" name="selected[]" onChange="myFunction(this)" class="<?php echo $row['state_point'];?>"> 
        </td> 
        <td bgcolor="#FFFFFF" align="center"><span class="subdetails"><?php echo $i++; ?></span></td> 
        <td bgcolor="#FFFFFF" align="left"><span class="subdetails"><?php echo $row['leader_name']; ?></span></td> 
        <td bgcolor="#FFFFFF" align="left"><?php echo $row['facebook']; ?></td> 
        <td bgcolor="#FFFFFF" align="left"><?php echo $row['twitter']; ?></td> 
        <td bgcolor="#FFFFFF" align="left" class="<?php echo $row['state_point'];?>" ><?php echo $row['state_point'];?> 



    </td> 
        <td align="center" bgcolor="#FFFFFF"><a href='#'><img style='vertical-align:bottom;' src='images/view profile.png' width='10' height='10' border='0'></td> 
        <td align="center" bgcolor="#FFFFFF"><input type="radio" name="pm" value="pm"></td> 
       </tr> 

    <?php } ?> 
    <tr> 
        <td align="center" bgcolor="#FFFFFF">Remaining Budget : </td> 
        <td align="center" bgcolor="#FFFFFF"><span id="total" class="0">1000</span></td> 
        <td> 
        </td> 

       </tr> 
       <tr> 
        <td align="center" bgcolor="#FFFFFF"><input type="submit" name="add" value="Add Team"> </td> 
        <td align="center" bgcolor="#FFFFFF"><input type="reset" value="Clear Team" onClick="javascript:changeTextToBlack();"></td> 
       </tr> 
       </table> 
    </form> 

這是我的表的代碼,我想在 改變它選擇的下拉列表時,會自動改變價值的地方,在地方州的聯邦,其他領域保持相同的,因爲它是,只有在改變值列

+0

請在這裏發佈您的代碼... – Nirmal

回答

0

是的,這是可以做到的。使用JavaScript/AJAX和HTML:

<select id="text" name="hub" onChange="refine_search();"> 
    <option value="test1">test1</test1> 
    <option value="test2">test2</test2> 
    <option value="test3">test3</test3> 
</select> 

現在JavaScript代碼refine_search()功能:

function refine_search(x) 
{ 
    var temp_test=document.getElementById('test'); 
    test=temp_test.options[temp_test.selectedIndex].value; 

    /*Copy this entire code from here this is an AJAX Call*/ 
    var xmlHttp; 
    try{  
     xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari 
    }catch (e){ 
     try{ 
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer 
     }catch (e){ 
      try{ 
       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
      }catch (e){ 
       alert("No AJAX!?"); 
       return false; 
      } 
     } 
    } 
    var url="www.google.com";// url which contains the next server side page to query 
    xmlHttp.open("GET",url,true); 
    xmlHttp.onreadystatechange=function(){ 
     if (this.readyState == 4) //when the page responds back 
     { 
      //change to this page. 
     } 
    } 
    xmlHttp.send(null); 
} 

這將做要緊

0

試試這個。

<select id="text" name="sel" onChange="reloadPage();"> 
     <option value="a" <? echo ($_GET['sel'] == 'a' ? 'selected="selected"' : '') ?> >test1</test1> 
     <option value="b" <? echo ($_GET['sel'] == 'b' ? 'selected="selected"' : '') ?>>test2</test2> 

    </select> 

並添加此

function reloadPage() 
{ 
    document.frm_change.method = 'get'; 
    document.frm_change.submit(); 
} 

當表單將提交SEL期權的價值會自動選擇,無需AJAX的。