且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

阻止使用javascript重定向/刷新表单提交

更新时间:2023-10-21 20:45:52

答案是(感谢Ulysses回答部分问题):

 < form id =editFormname =editFormonsubmit =onSave(); return false;> 

我的onSave();函数确实返回false,但由于它正在进行重定向,所以我不得不在onSave()之后返回false。 (解释为什么??)

谢谢!


I have a page where you can enter data within a series of texboxes (generated from php), and 2 buttons, GetData and SaveData. I want to be able to press enter when editing the texboxes, and it would perform the same action as clicking the SaveData button (onclick="onSave();"). I can acheive this by doing the following:

<form id="editForm" name="editForm" action="onSave();">

but when I press enter, the page is redirected to the page, without the php post (ex.:www.mypage.com/index.php, instead of www.mypage.com/index.php?edit_data=true)

How do I achieve what I want?

The answer was (thanks to Ulysses for part fo the answer):

<form id="editForm" name="editForm" onsubmit="onSave();return false;">

My onSave(); function did return false, but since it was doing the redirection, I had to put the return false after the onSave(); (explain why??)

Thanks!