简体   繁体   English

将数据从javascript弹出式多行文本框中传输到选择控件

[英]transfer data from javascript popup multiline textbox to a select control

I am trying to transfer data from a multiline textbox to a select control. 我正在尝试将数据从多行文本框中传输到选择控件。 The multiline textbox appears as a popup and I want all the records pasted in the textbox to be transferred to the select control once the user will click submit in the popup window. 多行文本框显示为弹出窗口,一旦用户单击弹出窗口中的“提交”,我希望将粘贴在文本框中的所有记录转移到select控件中。 Probably with jquery or javascript, or maybe something else. 可能与jquery或javascript或其他有关。 The page is built in MVC3 Razor. 该页面是在MVC3 Razor中构建的。 Here is the code from the page: 这是页面中的代码:

The script for the popup control: 弹出控件的脚本:

<script type="text/javascript">
    $(function () {
        $("a[id^=opener]").click(function () {
                    $("#dialog").dialog('destroy');
                    $("#dialog").attr("title", "Please paste your products")
                    .html("<p><textarea name=\"TextMessage\" rows=\"10\" cols=\"72\" /><br /><input type=\"submit\" value=\"Submit\" /></p>");

                    $("#dialog").dialog({
                        height: 420,
                        width: 650,
                        modal: true
                    });
        });

    });
</script>

The .cshtml page: .cshtml页面:

@using (Html.BeginForm("ASPXView", "Report", FormMethod.Post)) {
    @Html.ValidationSummary(true, "Password change was unsuccessful. Please correct the errors and try again.")
    <div>
        @Html.Hidden("Id", Model.Report.Id)
        <div id="accordion">
        @{int i=0;}
            @foreach (var item in Model.Parameters)
            {
                <h3><a href="#">@Html.LabelFor(m => item.Name, item.Prompt)</a></h3>
                <div>
                    <div class="editor-label">
                        Search @*Html.TextBox("Search")*@ 
                        <input id="@("Search" + item.Name)" type="text" name="q" data-autocomplete="@Url.Action("QuickSearch/" + item.Name, "Report")" />
                    </div>

                    <div class="editor-field">
                        <select multiple id="@("Select" +item.Name)" name="@("Select" +item.Name)"></select>                           
                    </div>

                    <div class="removed" style="clear:both; float:left; margin-left:440px;">  
                     <a href="#" class="remove">Remove selection</a>   
                     <a id= "opener@(i)" class="OpenDialogClass" href="#" >Open Dialog</a>           
                    </div>    

                </div>
                i++;
            }         
        </div>
        <p style="text-align: right">
            <input type="submit" value="Generate Report" />
        </p>
    </div>
}
<div id="dialog" title="Basic dialog">
</div>

Screenshot from the page: 页面截图:

在此处输入图片说明

So the data which will be pasted in the popup textbox, I would like to have it in the select control once the submit button is clicked. 因此,将要粘贴在弹出文本框中的数据,一旦单击提交按钮,我想将其保存在选择控件中。 Any idea how I can do that? 知道我该怎么做吗? Thanks in advance, Laziale 在此先感谢Laziale

You could serialize the contents of the textarea and then do what you need to do with it (Post it to a controller or perhaps hand it off to the underlying page somewhere) 您可以序列化textarea的内容,然后执行所需的操作(将其发布到控制器,或者将其传递到某个地方的基础页面)

$('form').submit(function(e){
   e.preventDefault();
   e.stopPropagation();

   var o = {};
   $( $('textarea').val().split(/\n|\r/) ).each(function(i){
      o[i] = this;
    });   
    var jsonString = JSON.stringify(o);   

    // DO SOMETHING WITH JSON OBJECT HERE
});​

http://jsfiddle.net/vUH3a/ http://jsfiddle.net/vUH3a/

This will give you a start. 这将给您一个开始。

$("Button Selector").click(function(){
var SelectOptions= [];
        $("list Selector").each(function () {
            SelectOptions.push($(this).attr('id'));
        });
SelectOptions.each(function () {
            //build your mark up here and return
        });
});

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

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