Javascript没有提交Html表单

时间:2013-02-13 06:00:53

标签: php javascript html

我正在使用以下javascript提交表单,但它没有提交。

 if(timeup)
        {
         alert("welcome to time up.");
        var id = document.getElementById("test_id").value;
        var no = document.getElementById("noq").value;
      var action = 'result.php?id='+id+'&no='+no+'';

    exercisenew.action = action;
    alert("form"+exercisenew.action);
   exercisenew.submit();
       alert("form submitted.");
    }

完整代码here

Html表单。

<form method="post" action="" id="exercisenew" name="exercisenew">

2 个答案:

答案 0 :(得分:1)

if(timeup)
{
  alert("welcome to time up.");
  var id = document.getElementById("test_id").value;
  var no = document.getElementById("noq").value;

  //use encodeURIComponent()
  var action = encodeURIComponent('result.php?id='+id+'&no='+no+'');

  //get the form
  var exercisenew = document.getElementById("exercisenew")
  exercisenew.action = action;

  alert("form"+exercisenew.action);
  exercisenew.submit();
  alert("form submitted.");
}

答案 1 :(得分:0)

exercisenew

创建对象
var exercisenew = document.getElementById("exercisenew")

并完成你所做的所有事情