更改隐藏字段的值后提交表单数据

时间:2013-10-23 13:15:46

标签: javascript forms angularjs

我有一个简单的html表单:

<form id="formD" action="/somewhere" method="POST">
  <input type="hidden" name="i[value]" ng-model="i.value" value={{i.value}}
  <button type="button" ng-click="changevalue()) Change Value

使用表单控制器:

function myFormController($scope) 
{
  $scope.saveAsDraft = function(){
    $scope.i.value="true";
    console.log($scope);
    document.getElementById("formD").submit();
  };
}

在检查控制台日志时,value正在$scope内更改,但提交后,i.value始终为空!我在哪里弄错了?

我采用的另一种方法是将输入字段设为文本:

<input type='text' name="i[value]" id="something" 
       ng-model='i.value' style="display:none;">

请帮忙。如何在提交表单数据之前更改此隐藏字段的值?

1 个答案:

答案 0 :(得分:0)

您使用逗号分隔属性。那是不对的。它们应该用空格 分隔,如下例所示:

<input type="text" name="i[value]" id="something" 
       ng-model="i.value" style="display:none;">