开发者

using multiple submit buttons in a form

I have a form with two button .I want to redirect to two different pages when i click these button.On the click event of both buttons i am executing a sa开发者_运维知识库me function.I want that the function should be executed first then it should be redirected to respective page


you could change action of form on the fly during submitting (and answer varies depending on using jquery, pure javascript etc.)

but I recommend using php for that task

<input type="submit" value="Edit" class="spare" name="edit">
<input type="submit" value="Send" class="spare" name="send">

and then:

if (isset($_POST['edit']))
    ...
elseif(isset($_POST['send']))
    ...


Try this:

  <input type="button" value="Edit" class="spare" onclick="check('edit')">
  <input type="button" value="Send" class="spare" onclick="check('send')">

Where with check() will add the action to the form and then submit it:

function check(action){
   var form = document.getElementById('formId');
   form.action = 'http://needed/url/' + action;
   form.submit();
}

Hope it solves your problem :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜