2012-02-07 290 views
2

我在製作一個搜索結果頁面。簡要介紹一下,我有一個登錄頁面,它將引導你到另一個頁面(比如說主頁)。這個頁面包含1個下拉框(和),1個文本框,1個按鈕和1個iframe,其中包含我擁有的頁面我的桌子。現在我有一個在該表上顯示的具有名字,姓氏和中間名的頭部的用戶列表,這是所有數據在啓動時顯示的。現在,我從下拉框中選擇了名字,然後輸入我的名字結果爲那些與我的名字相同的人過濾。我在我的表格頁面上使用了一個過濾器,我在其中添加了參數,例如//localhost/test/table.php?fname=test動態更改iframe的src內容

現在的事情是,iframe應該是唯一一個將改變使我的主頁完好無損。現在,iframe src將根據我在下拉框中選擇的內容進行更改,如我之前所述,不使用表單提交,並且值將基於文本框上的文本。並且如果可能的話,不要在src鏈接上使用http://。

嗯,我幾乎做的onclick的部分將使用該腳本更改的iframe頁面:

<script type='text/javascript'> 
     function goTo(){ 
     top.table.location = 'http://localhost/test/home.php; 
     } 
     </script> 

它應該是這樣的:

$dropdownvalue = dropdownselectedtext 
$textvalue = valueoftextbox 

//localhost/test/table.php?$dropdownvalue$textvalue 

那麼這裏是我的第一部作品。爲更好的理解發表評論。假設'#'後面跟着文本意味着一些價值。以供參考。

$acct_no = "#LOG_IN_ID OF USER"; 

      echo "<script type='text/javascript'> 
      function goTo(){ 
      top.table.src = '#SOMEURLHERE'; 
      } 
      </script>"; 

      echo "<table border='0' align='center' bgcolor='#ffffff' width='800px'> 
      <tr> 
       <td style='padding-left:30px;padding-top:20px;'> 
        <h3>SELECTION TEST</h3> 
       </td> 
       <td align='right' style='padding-right:30px;' height='120px'> 
        <select name='filter' id='filter'> 
         <option value='fname'>fname</option> 
         <option value='lname'>lname</option> 
         <option value='mname'>mname</option> 
        </select> 
        <input type='text' value='Enter text here' id='textbox'> 
        &nbsp; 
        <input type='button' value='Search' onClick='goTo();'> //this should give me the filters e.g: #SOMEURLHERE.php?#selectedfiltervalue=#textboxvalue 
       </td> 
      </tr> 
      <tr> 
       <td colspan='2' align='center'> 
        <iframe src='table.php?ref=$acct_no' name='table' width='730px' height='300px' frameborder='0'></iframe> 
       </td> 
      </tr> 
      </table>"; 

回答

1

我建議你將PHP容器以外的容器保存在<script>之外。

<script type="text/js" language="javascript"> 
    //Your function goes here 
</script 

<?php echo "<form name='someName' action='#'> 
echo "<table border='0' align='center' bgcolor='#ffffff' width='800px'> 
<tr> 
    <td style='padding-left:30px;padding-top:20px;'> 
     <h3>SELECTION TEST</h3> 
    </td> 
    <td align='right' style='padding-right:30px;' height='120px'> 
     <select name='filter' id='filter'> 
    <option value='fname'>fname</option> 
    <option value='lname'>lname</option> 
    <option value='mname'>mname</option> 
     </select> 
     <input type='text' value='Enter text here' id='textbox'> 
     &nbsp; 
     <input type='button' value='Search' onClick='javascript: return goTo(\"this.parent.filter.value, this.parent.textbox.value\");'> //this should give me the filters e.g: #SOMEURLHERE.php?#selectedfiltervalue=#textboxvalue 
    </td> 
</tr> 
<tr> 
    <td colspan='2' align='center'> 
     <iframe src='' name='table' width='730px' height='300px' frameborder='0'></iframe> 
    </td> 
</tr> 
</table></form>";?> 

你沒有使用你的整個截面<form>標籤,所以管理領域是困難的。另外,請嘗試在以前的文章中定義的JavaScript。

1

嘗試中的onclick在下拉框中使用本/ onChange處理(每個值):

javascript: return goto(\"$dropdownvalue\", \"$textvalue\");

而且,將其集成到

<script type='text/javascript'> 
    function goto(var1, var2){ 
     finLink = "http://localhost/test/table.php?" + var1 + var2 
     top.table.location = finLink; //Not sure if it will be top.table.location or top.table.src 
    } 
</script> 
+0

謝謝,但缺少一些東西,很好,因爲我有一個按鈕,當點擊時,我將更改iframe內容。現在我怎樣才能得到我的下拉菜單的價值?就像你可以看到的那樣,我將使用它在地址欄中手動傳遞值。我很困惑。 – KaHeL 2012-02-07 09:59:55

+0

然後,您可以發佈整個和<按鈕部分>的代碼嗎? – hjpotter92 2012-02-07 10:15:39

+0

完成編輯我的問題。代碼已添加供您參考。 – KaHeL 2012-02-07 10:38:13

0

您可以使用jquery爲此:

$('#myiframeid').attr('src', 'http://some.url.here'); 
+0

對我沒有用處,因爲你可以看到我已經使用javascript完成了這部分工作,我需要的是動態更改iframe onclick的src,並將我的變量值加起來。 – KaHeL 2012-02-07 10:48:31