導航:首頁 > 編程語言 > js表單提交時驗證

js表單提交時驗證

發布時間:2021-04-04 12:08:14

① 用js提交表單時如何驗證表單項

都可以的,在以上的代碼裡面可以,在obsubmit代碼裡面也可以,例如可以:

function selectByMoreC(Action){
document.forms["salChanceForm"].method = "post";
document.forms["salChanceForm"].action = Action;
if (document.forms["salChanceForm"].myinput.value.match(/[^0-9]/))
{
alert('xxx只能輸專入數屬字!');
}//還可以添加其它一些欄位的判斷
else document.forms["salChanceForm"].submit();
}

② 如何在form中調用js表單驗證

|

比如有個表單

<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>


js驗證函數:

function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}


當提交表單的回時候就會觸答發驗證,運行結果:

③ js form表單提交驗證

|

$("form").submit(function(e){

if(!($('userName').val()=="預設的值"||$('password').val()=="預設的值")){
alert('用戶名密碼不對!內');
e.preventDefault();
}
});

請引入jquery~

望采容納~~

④ js驗證和提交表單問題,驗證的了提交不了,提交了了,驗證無效

可以跟蹤一下

js方法裡面加如:
windows.open("1.html");
或列印小窗什麼的。一點點跟下去,看出問題在哪

javaScript表單驗證與提交

<form action='a.aspx' onsubmit='return chk()'>
<input type='text' name='uname' id='uname'/>
<input type='text' name='upwd' id='upwd'/>
</input type='submit' value='提交'/>
</form>
<script>
function chk()
{
var u = document.getElementById('uname').value;
var p = document.getElementById('upwd').value;
if(u=='')
{
alert('請填寫用戶名');
return false;
}
if(p=='')
{
alert('請填寫密碼');
return false;
}
return true;
}
</script>
a.aspx.cs
string uname = Request.Form["uname"];
string upwd= Request.Form["upwd"];

⑥ 提交表單時,怎麼控制先進行JS驗證,如果通過JS驗證再連接伺服器執行PHP語句呢

我把代碼都寫在一個文件裡面 命名為 test.php 你可以測試一下 我只是寫了個意思 具體的操作你可以自己再寫 我測試沒問題了

<html>
<head>
<script type="text/javascript" src="update.js"></script>
<form action = "update.php" method = "POST">
</form>
</head>
<body>
<form action = "test.php" onsubmit="return my_check();" method = "POST">
<table>
<tr><td><label for = "id">文件號:</label></td><td><input type = "text" size="8" name = "id" id='my_id' /></td></tr>
<tr><td><label for = "user">姓名:</label></td><td><input type = "text" size = "8" name = "user" /></td></tr>
<tr><td><input type = "submit" name = "submit" value = "提交更新"/>
<input type = "hidden" name = "action" value = "add" />
<input type = "reset" name = "reset" value = "重新填寫" /></td></tr>
</table>
</form>
</body>
</html>

<script language=javascript>
function my_check(){
var a = document.getElementById("my_id");
if(a.value==""){
alert ("文件號不能為空"+"\n"+"請加上");
a.focus();
return(false);
}
else{
return(true);
}
}
</script>

<?
$act = $_POST['action'];
if($act == 'add'){
$id = $_POST['id'];
echo "您輸入了".$id;
}
?>

⑦ jsp關於js注冊表單驗證問題:事件為submit按鈕提交驗證的onClick事件,先看一下部分主要代碼:

click裡面應該加上return,如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<script type="text/javascript">
function check(){
var name=document.form.username.value;
if(name=='')
{
alert("no null!");
return false;
}
else{

alert("hello world!");

}
}
</script>
<body>

</head>
<body>
<form action="test2.jsp" name="form" method="post" >
輸入用戶名:<input name="username" type="text" onblur="check()"/>
用戶姓名:<input name="name" type="text"/>
<input type="submit" name="Submit" value="登錄" onclick="return check();"/>
</form>
</body>
</html>

最好還是在onsubmit驗證,因為有時候是直接回車提交的,不一定按按鈕,如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<script type="text/javascript">
function check(){
var name=document.form.username.value;
if(name=='')
{
alert("no null!");
return false;
}
else{

alert("hello world!");

}
}
</script>
<body>

</head>
<body>
<form action="test2.jsp" name="form" method="post" onsubmit="return check();">
輸入用戶名:<input name="username" type="text" onblur="check()"/>
用戶姓名:<input name="name" type="text"/>
<input type="submit" name="Submit" value="登錄" />
</form>
</body>
</html>

⑧ JS表單驗證

你失去焦點驗證寫好了,就點擊注冊再驗證一邊,把驗證的代碼封裝好,然後返回一個bool值判斷是否通過驗證,然後如果全部通過就提交表單,否則就不提交表單

⑨ JavaScript表單提交驗證

你應該直接在登錄按鈕的click事件中寫:

<script>
$("#login").click(function(){
//把你的三個驗證所用到的代碼,放到這里來,最主要是一旦驗不通過就returnfalse;反之就往下運行
//用if也可以,用switch也可以,你這樣三個方法分別是是笨方法哦!
});
</script>

⑩ javascript提交表單時驗證

function validate(){
var t1 = document.getElementById('select_cn');
var t2 = document.getElementById('select_wsrs');
var t1val =document.getElementById('gnmj');
var t2val =document.getElementById('syrs');

if(t1.style.display=='block'&&t2.style.display=='block'&&(t1val.value==''||t2val.value=='')){
alert("2個都不能為空");return false;
}else if(t1.style.display=='block'&&t1val.value==''){
alert("第1個不能為空");return false;
}else if(t2.style.display=='block'&&t2val.value==''){
alert("第2個不能為空");return false;
}else{
alert("提交");return true;
}

}
<input type="radio" onclick="showdiv1()" name="aaa"/>選擇第1個單選按鈕
<input type="radio" onclick="showdiv2()" name="aaa"/>選擇第2個單選按鈕
<input type="radio" onclick="showdiv12()" name="aaa"/>選擇第3個單選按鈕

<input id="select_submit" type="submit" value="確定" onclick="return validate();" style="display:none" />

閱讀全文

與js表單提交時驗證相關的資料

熱點內容
copy文件從我的電腦到別的電腦 瀏覽:55
手機數據什麼情況覆蓋 瀏覽:312
pyqt用什麼軟體編程 瀏覽:500
專業少兒編程培訓課程幫助是什麼 瀏覽:311
數控機床系統編程用什麼軟體 瀏覽:986
計算機編程社團如何展示 瀏覽:94
iosqq文件怎麼打開 瀏覽:872
怎麼看文件多少g 瀏覽:868
編程哪個是直播課 瀏覽:159
點上傳文件沒反應 瀏覽:686
6s無id密碼怎麼定位 瀏覽:33
wifi萬能顯示密碼嗎 瀏覽:574
linux查看php文件內容 瀏覽:389
win10無法連接到寬頻 瀏覽:811
濟南編程軟體哪個好 瀏覽:695
三張報表中數據是怎麼串聯的 瀏覽:971
紅頭文件寄多少份 瀏覽:92
js路徑作為參數 瀏覽:671
pscs6圓角工具 瀏覽:639
天天酷跑怎麼快速升級 瀏覽:457

友情鏈接