简体   繁体   English

jQuery UI对话框-传递动态变量并更改html对话框形式

[英]Jquery UI Dialog - Passing Dynamic Variable and changing dialog form html

I have a upload document dialog created with jqueryUI that works great, but I need to add it to a page with multiple tabs, and rotate the default document type in the drop down box as well as change a hidden value in the form that is used by the form validation (primarily to return to the correct tab after upload). 我有一个使用jqueryUI创建的上传文档对话框,效果很好,但是我需要将其添加到具有多个选项卡的页面中,并在下拉框中旋转默认文档类型,以及更改所使用表单中的隐藏值通过表单验证(上传后主要返回正确的标签)。

I could just create a dozen of these slightly re-named at the bottom of the page so that each dialog is unique, from each unique button click, but that creates a lot of unnecessary bloat on a page that is already probably too large. 我可以在页面底部创建一些稍微重命名的名称,以便每个对话框在每次单击按钮时都是唯一的,但这会在页面上已经造成太大的不必要的膨胀。

What I really want is to pass a number in the source click that automatically changes the hidden input field and changes the default dropbox selection (they are directly related) 我真正想要的是在源点击中传递一个数字,该数字会自动更改隐藏的输入字段并更改默认的保管箱选择(它们是直接相关的)

Unfortunately my coding skills are still noobish, I am pretty good with php but javascript and ajax are still kinda new to me. 不幸的是,我的编码技能仍然很笨拙,我对php相当满意,但是javascript和ajax对我来说还是一个新手。 This is an internal office document sharing system between remote offices, I only get to code part time so unfortunately I get a bit rusty... :) 这是远程办公室之间的内部办公室文档共享系统,我只能兼职编写代码,所以不幸的是我有点生锈... :)

<div id="upload" title="Upload Documents" style="margin: 0 0 0 0" ><div id="upload-Wrapper"><p >To add documents, please select your document on your computer and enter a description and classification.&nbsp;Maximum file size is 25 megabytes per document uploaded.</p>

<form action="updoc.php" enctype="multipart/form-data" method="post">
<div class="auto-style2">
<br/><label>Select Document</label><input type="file" name="pdfdoc" value="" style="width: 279px" />
<br/>   <br/>
<label style="width: 113px">Document Type</label>
<select name="doc_type" id="doc_type" style="width: 281px">
<option value="T">RT</option> <!--This is the default value for the first tab, but on others I need to rotate the list so the correct one is default-->
<option value="C">CT</option>
<option value="A">TA</option>
<option value="P">PA</option>
<option value="D">AD</option>
<option value="H">DH</option>
<option value="L">LW</option>
<option value="V">LWD</option>
<option value="W">LWT</option>
<option value="R">PR</option>
<option value="O">Other</option>
</select>
<br/>   <br/>
<label style="width: 140px">Description </label>
<input type="text" name="pdfdesc" value="" style="width: 309px" />
<br/>
<p>*all fields required  
<input type='hidden' value='3' name='tab' /> <!--This is the hidden value I need to change depending on the source click-->
<input type="submit" name="submit" value="Upload File" style="float:none; margin-left: 85px"  /></p>
</div>
</form>
</div><!--end Contact-Wrapper-->
</div>

<script>
var dialogOpts = {
bgiframe: true,
autoOpen: false,
modal: true,
width: "521px"
};

$('#upload').dialog(dialogOpts);
$('#upload-Links').click(function() {
  $('#upload').dialog('open');
  return false;
});
</script>

Your question is not very clear. 您的问题不是很清楚。 What do you mean by the "source click"? 您所说的“来源点击”是什么意思?

Out of what I understood, here's what I came up with. 根据我的理解,这就是我的想法。 The following script will change the dropdown to CT when a .txt file is selected, and to TA when a .png file is selected. 以下脚本将在选择.txt文件时将下拉菜单更改为CT ,而在选择.png文件时将下拉菜单更改为TA

No matter what file is selected the filename will be put into the hidden field. 无论选择了哪个文件,文件名都会放入隐藏字段中。

$('input[name=pdfdoc]').change(function() {
    var f = $(this).val(); // file name
    var dt = $('#doc_type'); // drop down
    switch (f.split('.').pop()) { // check the file extension
        case 'txt':
            dt.val('C');
            break;
        case 'png':
            dt.val('A');
            break;
    }
    $('input[name=tab]').val(f); // store the file name in the hidden field
});

Let me know if this is not exactly what you were looking for - I'll update the answer. 让我知道这是否不是您想要的东西-我将更新答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM