0
我是一個新手 - 我試圖在爲用戶加載變量時自動填充模態字段值。我有一個預感,我需要在加載時將.val()添加到對話框,但不確定。目前我正在嘗試加載像標準表單一樣的值。感謝您的幫助,您可以給我這個 -用javascript變量填充jquery模態表單域值
按鍵,啓動模式:
<input type="button" id="reply_clicky" name="emailmessage" onClick="updateReplyName('{{email.sender}}')" value="Reply" >
表:
<div id="reply_form" title="Send Message">
<form id="replyemailform" method="POST" action="/sendemailmessage" name="emailposting">
<p>
<label for="recipient">To:</label>
<input type="text" name="recipient" id="recipient">
</p>
<p>
<label for="subject">Subject: </label>
<input type="text" name="subject" id="subject">
</p>
<p>
<label for="content">Message: </label>
<textarea name="content" id ="content" class="textarea" rows="4" style=""></textarea>
</p>
</form>
</div>
的Javascript:
$(document).ready(function(){
$('#reply_form').dialog({
autoOpen: false,
height: 375,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}},
{
text: "Submit",
click: function() {
$('#replyemailform').submit();
}}
]
});
$('#reply_clicky').button().click(function(e){
$('#reply_form').dialog('open');
});
});
function updateReplyName(sender){
console.log("updateReplyName function fired");
document.getElementById('recipient').value = sender;
}
編輯包含DevlshOne的建議:
$(document).ready(function(){
$('#reply_form').dialog({
autoOpen: false,
height: 375,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}},
{
text: "Submit",
click: function() {
$('#replyemailform').submit();
}}
]
});
$('#reply_clicky').button().click(function(e){
$('#reply_form').dialog({
open: function(e, ui) {
$('#recipient').val('value is here');
}
});
$('#reply_form').dialog('open');
});
});
凡'sender'被分配一個值? – DevlshOne
我的想法是將{{email.sender}}傳遞給以{{email.sender}}作爲參數的updateReplyName函數...將其命名爲「sender」...也許我沒有正確傳遞它? –
只要在您打開對話框之前指派'sender',就可以使用我在下面發佈的答案。 – DevlshOne