2013-03-28 33 views
0

我開發一個PHP應用程序,使用梅西,一個jQuery彈出對話框:http://marcosesperon.es/apps/messi/梅西彈出框,內置HTML和Javascript

在我的申請,我有一個價格表,我想使編輯。這個想法是,當他們點擊一個按鈕,梅西彈出框出現,他們可以選擇一些選項,並輸入數據,然後將其添加到表中。

我已經到了你點擊按鈕的階段,並且出現了messi彈出框,顯示用戶可以選擇不同選項的選擇框。

代碼如下:

function new_header() 
{ 
    var content = "<form class='format_form' action='add_category.php' method='POST'> 
         <fieldset> 
          <legend>Choose a Pricing Category</legend> 

          <ol> 
           <li> 
            <label for='category'>Category</label> 

            <select id='category' name='category'> 
             <option value='short_break'>Short Break</option> 
             <option value='nightly_rate'>Nightly Rate</option> 
             <option value='percentage_off'>Percentage Off</option> 
             <option value='free_nights'>Free Nights</option> 
            </select> 
           </li> 
          </ol> 
         </fieldset> 

         <fieldset> 
          <button type='submit' name='add_category' onclick='return validate_form();' id='add_category'>Add the Pricing Category</button> 
         </fieldset> 
        </form>"; 

    new Messi(content, {title: "Add a New Pricing Category", modal: true, width: '650px'}); 
} 

在該表是一個可點擊的圖像,彈出梅西彈出對話框,代碼如下:

<th scope="col" class="rounded-topright"> 
    <img class='hover_off' src='../../../includes/images/table/add_header.png' width='25px' height='25px'> 

    <a href='#' onclick='new_header()'> 
     <img class='hover_on' src='../../../includes/images/table/add_header_hover.png' width='25px' height='25px'> 
    </a> 
</th> 

隨後出現在梅西內容彈出框取決於用戶在選擇框中的選擇。作爲測試,我試圖使系統彈出一個JavaScript警告時,選擇框選項更改,就像這樣:

$(document).ready(function() 
{ 
    var category_number; 

    $("#category").change(function() //When the category is changed 
    { 
     category_number = document.getElementById('category').selectedIndex;  //Get the property location in the array 

     alert(category_number); 
    }); 
}); 

我第一次嘗試把這個代碼的js文件我都另一個javascript in,然後當它不起作用時,我將它放入.php文件中,原始定價計劃表放在裏面,但那也行不通。

任何人都可以幫忙嗎?或者失敗了,想出一個更好的方法來實現我的目標?

回答

0

通過添加固定的問題:

onchange='category_change(this)' 

入選擇框的屬性,然後創建函數category_change()處理所選擇的選項。

0

嘗試增加:

var category_number; 

$("#category").change(function() //When the category is changed 
{ 
    category_number = document.getElementById('category').selectedIndex;  //Get the property location in the array 

    alert(category_number); 
}); 

var content並與梅西彈出推出他們兩個