0

I am using jsPlumb and form2js. There are input fields inside the shapes, my problem is I cannot get the data from these input fields.

This flowchart editor is based here

This is the html for the div with inputs that I cannot get.

<div class="window task" style="left: 120px; top:200px; display:none;" data-nodetype="task" id="taskcontainer0">
        <div class="ctrl_container">
            <div class="button_remove">x</div>
        </div>
        <div class="details_container">
            <label class="detail_label">Name</label>
            <input type = "text" class="detail_text" name = "diagram.task.Title[]"/><br/>
            <label class = "detail_label">Description</label>
            <input type = "text" class ="detail_text" name = "diagram.task.Msg[]">
        </div>
    </div>

I need to convert the data inside the input field to JSON.

I am new to this. Thanks

Community
  • 1
  • 1
jihyo
  • 37
  • 6
  • Answers in this post may be help you. http://stackoverflow.com/questions/1184624/convert-form-data-to-js-object-with-jquery – iPao Aug 29 '14 at 04:03

2 Answers2

0

Check-out this post: Serialize form to JSON with jQuery

It's got a jsfiddle that seems to work quite well: http://jsfiddle.net/sxGtM/3/

0

how about this :

<div class="window task" style="left: 120px; top:200px; display:block;" data-nodetype="task" id="taskcontainer0">
    <div class="ctrl_container">
        <div class="button_remove">x</div>
    </div>
    <div class="details_container">
        <form id="myForm">
        <label class="detail_label">Name</label>
        <input id="title" type="text" class="detail_text" name = "diagram.task.Title[]" value="yes"/><br/>
        <label class = "detail_label">Description</label>
        <input id="msg" type="text" class ="detail_text" name = "diagram.task.Msg[]" value="no">
            </form>
    </div>
</div>
<pre class="result"></pre>
<pre id="json"></pre>

and the JS part

var title = $('#title').val();
var msg = $('#msg').val();
$('.result').text(title+"\n"+msg);

var form = $('#myForm').serializeArray();
var json = JSON.stringify(form);
$('#json').text(json);

Working demo here - jsfiddle

Azizi Musa
  • 1,009
  • 2
  • 10
  • 31