By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

The entered dijit value doesn't display the Json string, need solution thanks million

P: 12
Expand|Select|Wrap|Line Numbers
  1. MY HTML CODE:
  2. <script>
  3. require(["dojo/parser", "dojo/json",
  4.                          "dijit/form/FilteringSelect",
  5.                          "dijit/form/TextBox",
  6.                          "dijit/form/Textarea",
  7.                          "dijit/form/Button",
  8.                          "dijit/form/ValidationTextBox",
  9.                          "dijit/form/DateTextBox"]);
  10.         </script>    
  11.     </head>
  12.             <body class="claro" bgcolor="pink" onload='disablet()'>
  13.                 <h1>PRODUCT MASTER</h1>
  14.                 <div class="grouping" id="divid">
  15.  
  16.                 <label for="pcode">PRODUCT CODE:</label>
  17.                 <input type="text" name="pname" id="product code" value="" required="required"
  18.                 data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp:'[^\d{1,10}$]+', invalidMessage:'Invalid enter only number between 1-10.'" />
  19.                 <br>
  20.  
  21.                 <label for="pname">PRODUCT NAME:</label>
  22.                 <input type="text" name="pname" id="product name" value="" required="required"
  23.                 data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp:'[a-zA-z]+', invalidMessage:'Invalid enter only Text.'" />
  24.                 <br>
  25.  
  26.                 <label for="ptype">PRODUCT TYPE:</label>
  27.                 <select data-dojo-type="dijit/form/FilteringSelect" id="product type" name="ptype">
  28.                     <option value="rm">RAW MATERIALS</option>
  29.                     <option value="ip">INTERMEDIATE OPTION</option>
  30.                     <option value="fp">FINISHED PRODUCT</option>
  31.                 </select>
  32.                    <br>
  33.  
  34.                 <label for="unit">UNIT MEASUREMENT:</label>
  35.                 <select data-dojo-type="dijit/form/FilteringSelect" id="unit measurement" name="unit">
  36.                     <option value="kg">KG</option>
  37.                         <option value="G">G</option>
  38.                         <option value="t">TONE</option>
  39.                         <option value="m">Meter</option>
  40.                 </select>
  41.                 <br>
  42.  
  43.                 <label for="create">CREATED DATE:</label>
  44.                  <input type="text" name="CDATE" id="created date" value="1992-08-20" required="required"
  45.                 data-dojo-type="dijit/form/DateTextBox"/>
  46.                 <br>
  47.                 </div>
  48.                     <button id="UPDATE" value="UPDATE" onclick="UpdateJSON()">UPDATE</button>
  49.                     <h1>JSON</h1>
  50.         <span id="spnJSON"></span>
  51.     </body>
  52. </html>
MY JAVASCRIPT CODE:
Expand|Select|Wrap|Line Numbers
  1. function UpdateJSON() {
  2.  
  3.  
  4.     var json = {PRODUCTCODE : 2, PRODUCTNAME : 'dd', PRODUCTTYPE : 'fg', UNITMEASUREMENT : 'g', CREATEDDATE : '2007-12-05'};
  5.  
  6.  
  7.             var purchase = eval('(' + json + ')');
  8.             purchase.PRODUCTCODE=dijit.byId("product code").value;
  9.             purchase.PRODUCTNAME=dijit.byId("product name").value;
  10.             purchase.PRODUCTTYPE=dijit.byId("product type").value;
  11.             purchase.UNITMEASUREMENT=dijit.byId("unit measurement").value;
  12.             purchase.CREATEDDATE=dijit.byId("created date").value;
  13.  
  14.             json = JSON.stringify(purchase);
  15.             dojo.byId("spnJSON").innerHTML = json; 
  16.         }
  17.  
  18.  
Feb 20 '14 #1

✓ answered by Dormilich

problem #1, the "JSON" (line #4) is not a JSON string but already a JavaScript object (and it wouldn’t be valid JSON as well).

problem #2, line #8 - #12 make the original object obsolete (overwriting all values)

issue #3, if JavaScript encounters an error, you will find it listed in the error console (F12).

Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
problem #1, the "JSON" (line #4) is not a JSON string but already a JavaScript object (and it wouldn’t be valid JSON as well).

problem #2, line #8 - #12 make the original object obsolete (overwriting all values)

issue #3, if JavaScript encounters an error, you will find it listed in the error console (F12).
Feb 20 '14 #2

P: 12
Thanks Dormilich, I'm new to JSON and DOJO, Could you please so kind and modify my coding? Thanks in advance... :)
Feb 20 '14 #3

Dormilich
Expert Mod 5K+
P: 8,639
replace line #7 by var purchase = {};
Feb 21 '14 #4

P: 12
ya,dormilich i got it thankyou.
Expand|Select|Wrap|Line Numbers
  1. var jsonstr= {"productcode":dijit.byId("productcode").attr("value"),...}
Feb 21 '14 #5

Dormilich
Expert Mod 5K+
P: 8,639
technically, it’s still a JavaScript object.
Feb 21 '14 #6

Post your reply

Sign in to post your reply or Sign up for a free account.