2013-08-20 136 views
-1

我有一個表單將顯示配置文件信息,我有一個JavaScript將編輯表單。編輯工作正常,但不知道我現在做了什麼。我不是一個JavaScript專家,但我一直在試圖找出問題。 這裏是我的代碼:Javascript - 編輯表單問題

<script type="text/javascript"> 
    // Enable all the text fields, rename value of Edit button and submit the forms 

    function activate(){ 
     get_button_name = $("#save_button").text(); 

     if (get_button_name == 'Edit'){ 
     $(".enable").attr('disabled', false); 
     $("#save_button").text('Save'); 
     } 

     else { 
      $("#editProfileForm").submit(); 
     } 

    } 


    function search(){ 
     document.getElementById('button-name').value="search"; 
    } 

</script> 

<div id="profile_form"> 
    <form id="editProfileForm" method="get" action="/updateProfile/"> 
    {% csrf_token %} 
     <table> 
    <h1 style="margin-left: 40px;">Profile</h1> 

    <!-- Search box --> 
    <div id="search"> 
     <input type="text" name="search_input" id="search_input" style="display: inline;" /> 
     <button type="submit" onclick="search()">Search</button> 
    </div> 
    <input type="hidden" name="button-name" id="button-name" value="" /> 

    {% for i in profile %} 
    <tr> 
     <td><label>Firstname:</label></td> 
     <td><input class="enable" name="firstname" type="text" disabled value="{{ i.firstname }}" /></td> 
    </tr> 


    <tr>  
     <td><label>Lastname:</label></td> 
     <td><input class="enable" name="lastname" type="text" disabled value="{{ i.lastname }}" /></td> 
    </tr> 

    <tr> 
     <td><label>Email:</label></td> 
     <td><input class="enable" name="email" type="text" disabled value="{{ i.user.email}}" /></td> 
    </tr> 

    <tr> 

     <td><label>Location:</label></td> 
     <td><input class="enable" type="text" name="location" disabled value="{{ i.location }}" /></td> 
    </tr> 


    {% endfor %} 
    </table> 
    {% if edit %} 
    <button style="margin: 30px 30px" id='save_button' type='button' onclick='activate()'>Edit</button> 
    {% endif %} 
    </form> 

</div> 

這裏是我的代碼: http://jsfiddle.net/U5jhc/

+0

向我們提供有關您想要發生的事情的細節以及發生了什麼問題的更多信息會有所幫助。對於像這樣的小js問題,將代碼粘貼到jsfiddle(http://jsfiddle.net)中也是有幫助的,因此我們可以自己測試它。 –

+0

它顯示在窗體上的配置文件,例如value =「{{i.location}}」,用於顯示配置文件的位置。這使用Django。我想要做的是,當我點擊編輯按鈕時,它會讓我輸入表單,然後點擊保存並將新信息保存到數據庫中。問題是,當我點擊編輯時,它什麼都不做。 – amb1s1

+0

我從不使用jsfiddle.net。我看到四個窗口,我在哪裏放置代碼? – amb1s1

回答

0

我的問題是關於Django的設置。我有錯誤的設置導致jquery文件不加載。