输入的dijit值不会显示在Json字符串上

时间:2014-02-20 14:11:59

标签: javascript dojo

你能不能帮我找到问题,这里json字符串没有显示dijit字段值。

此处为HTML代码

    <script>
        require(["dojo/parser", "dojo/json",
                 "dijit/form/FilteringSelect",
                 "dijit/form/TextBox",
                 "dijit/form/Textarea",
                 "dijit/form/Button",
                 "dijit/form/ValidationTextBox",
                 "dijit/form/DateTextBox"]);
    </script>   
</head>
<body class="claro" bgcolor="pink" onload='disablet()'>
    <h1>PRODUCT MASTER</h1>
    <div class="grouping" id="divid">

        <label for="pcode">PRODUCT CODE:</label>
        <input type="text" name="pname" id="product code" value="" required="required"
        data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp:'[^\d{1,10}$]+', invalidMessage:'Invalid enter only number between 1-10.'" />
        <br>

        <label for="pname">PRODUCT NAME:</label>
        <input type="text" name="pname" id="product name" value="" required="required"
        data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp:'[a-zA-z]+', invalidMessage:'Invalid enter only Text.'" />
        <br>

        <label for="ptype">PRODUCT TYPE:</label>
        <select data-dojo-type="dijit/form/FilteringSelect" id="product type" name="ptype">
            <option value="rm">RAW MATERIALS</option>
            <option value="ip">INTERMEDIATE OPTION</option>
            <option value="fp">FINISHED PRODUCT</option>
        </select>
        <br>

        <label for="unit">UNIT MEASUREMENT:</label>
        <select data-dojo-type="dijit/form/FilteringSelect" id="unit measurement" name="unit">
            <option value="kg">KG</option>
            <option value="G">G</option>
            <option value="t">TONE</option>
            <option value="m">Meter</option>
        </select>
        <br>

        <label for="create">CREATED DATE:</label>
        <input type="text" name="CDATE" id="created date" value="1992-08-20" required="required"
               data-dojo-type="dijit/form/DateTextBox"/>
        <br>
    </div>
    <button id="UPDATE" value="UPDATE" onclick="UpdateJSON()">UPDATE</button>
    <h1>JSON</h1>
    <span id="spnJSON"></span>
</body>

javascript代码

function UpdateJSON() {

    var json = {PRODUCTCODE : 2, PRODUCTNAME : 'dd', PRODUCTTYPE : 'fg', UNITMEASUREMENT : 'g', CREATEDDATE : '2007-12-05'};

    var purchase = eval('(' + json + ')');
    purchase.PRODUCTCODE=dijit.byId("product code").value;
    purchase.PRODUCTNAME=dijit.byId("product name").value;
    purchase.PRODUCTTYPE=dijit.byId("product type").value;
    purchase.UNITMEASUREMENT=dijit.byId("unit measurement").value;
    purchase.CREATEDDATE=dijit.byId("created date").value;

    json = JSON.stringify(purchase);
    dojo.byId("spnJSON").innerHTML = json; 
}

1 个答案:

答案 0 :(得分:0)

您不能在元素ID中添加空格。这就是为什么dijit找不到它们。

也许你可以用下划线替换空格

<input type="text" name="pname" id="product_code" ...>

purchase.PRODUCTCODE = dijit.byId("product_code").value;