文字框不能为空.

拼多多优质客户 2007-12-13 05:02:17
我现有一个查找页面.我想做到使用者不填写内容时,不能查找.提示文本框不能为空.

现在的代码如下:


<form name="frmSearch" method="GET" action="PS_WEB_VOC7_VW_list.asp">
<input type="Hidden" name="a" value="search">
<input type="Hidden" name="value" value="1">
<input type="Hidden" name="SearchFor" value="">
<input type="Hidden" name="SearchOption" value="">
<input type="Hidden" name="SearchField" value="">
</form>


<b>搜索 。。。。。。: </b>    
<select id="ctlSearchField">
<option value="BILLNO" {$search_CGD_BILLNO}>单号</option>
</select>
 
<select id="ctlSearchOption">
<option value="Contains" {$search_contains_option_selected}>包含</option>

</select>
    
<input type=text size=20 name="ctlSearchFor" id="ctlSearchFor" {$search_searchfor}>
 
<span class=buttonborder><input type=button class="button" value="搜索" onClick="javascript: RunSearch();"></span>

请各位帮忙.多谢
...全文
233 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
新手分数有点少,对不住大家了。

谢谢各位
Go 旅城通票 2007-12-14
  • 打赏
  • 举报
回复
结帖!
  • 打赏
  • 举报
回复
谢谢各位。问题已解决。

主要是我的原因不能理解代码又没说清楚,谢谢各位帮助。
Go 旅城通票 2007-12-13
  • 打赏
  • 举报
回复
function       RunSearch(){  
//赋值
document.frmSearch.SearchFor.value=document.getElementById("ctlSearchFor").value;
document.frmSearch.SearchOption.value=document.getElementById("SearchOption").value;
document.frmSearch.SearchField.value=document.getElementById("SearchField").value;
var content=document.frmSearch.SearchFor.value;
//如果你想判断其他两个条件的话把下面的注释去掉
/* if(document.frmSearch.SearchOption.value=="")
{
alert("包含不能为空!");
return;//推出函数,防止表单提交
}
if(document.frmSearch.SearchField.value=="")
{
alert("单号不能为空!");
return;//推出函数,防止表单提交
}*/
if(content.replace(/(^\s*) ¦(\s*$)/g,"")==""){
alert("内容为空");
return; //推出函数 ,防止表单提交
}
document.forms.frmSearch.submit();//提交放这里
}
Go 旅城通票 2007-12-13
  • 打赏
  • 举报
回复
你是靠表单外的输入来判断的吧??

你要把表单外的值给表单内的隐藏字段赋值了提交时才有值啊


<html>
<head>
<title>单号</title>
<link REL="stylesheet" href="include/style.css" type="text/css">
</head>
<body topmargin=5 {$onload}>
{$includes}

{include_if_exists file="include/header.asp"}

<form name="frmSearch" method="GET" action="PS_WEB_VOC7_VW_list.asp">
<input type="Hidden" name="a" value="search">
<input type="Hidden" name="value" value="1">
<input type="Hidden" name="SearchFor" value="">
<input type="Hidden" name="SearchOption" value="">
<input type="Hidden" name="SearchField" value="">
</form>

<table align=center width=100% border=0 cellpadding=0 cellspacing=0>
<tr><td>

<table align=center width=100% border=0 cellpadding=4>
<tr><td>

</td></tr>

<tr><td align=right style="padding-right:15px">
{if $allow_export}
{/if}


{if $allow_export}
  
<a target="_blank" href="PS_WEB_VOC7_VW_export.asp" class="tablelinks3">输出结果</a>  
{/if}
</td></tr></table>
</td></tr>
<tr><td width=100%>
<table class="main_table2" align=center width=100% border=0 cellpadding=0 cellspacing=0>
<tr ><td align=center colspan=2>
{if $allow_search}
<table width=100% border=0 cellpadding=0 cellspacing=0 height=43px class=linedownbody>
<tr>
<td width=30 align=right class=darkshade2> </td>
<td width=22 valign=middle><img src="include/img/arrow_topmenu.gif"></td>
<td align=left valign=middle class="toplist" style="padding-top:2;padding-left:10px"">
<b>搜索 。。。。。。: </b>    
<select id="ctlSearchField">
<option value="CGD_BILLNO" {$search_CGD_BILLNO}>单号</option>
</select>
 
<select id="ctlSearchOption">
<option value="Contains" {$search_contains_option_selected}>包含</option>
</select>
    
<input type=text size=20 name="ctlSearchFor" id="ctlSearchFor" {$search_searchfor}>
 
<span class=buttonborder><input type=button class="button" value="搜索" onClick="javascript: RunSearch();"></span>
<script>
function RunSearch(){
//赋值
document.frmSearch.SearchFor.value=document.getElementById("ctlSearchFor").value;
document.frmSearch.SearchOption.value=document.getElementById("SearchOption").value;
document.frmSearch.SearchField.value=document.getElementById("SearchField").value;
var content=document.frmSearch.SearchFor.value;
//如果你想判断其他两个条件的话把下面的注释去掉
if(document.frmSearch.SearchOption.value=="")
{
alert("包含不能为空!");
return;//推出函数,防止表单提交
}
if(document.frmSearch.SearchField.value=="")
{
alert("单号不能为空!");
return;//推出函数,防止表单提交
}
if(content.replace(/(^\s*) ¦(\s*$)/g,"")==""){
alert("内容为空");
return; //推出函数 ,防止表单提交
}
document.forms.frmSearch.submit();//提交放这里
}
</script>
  • 打赏
  • 举报
回复
实在是水平太差,让各位见笑了。

我试了上面的方法,填入数值后,仍提示内容为空。

麻烦各位能尽量参照我上面原来的代码修改。多谢各位了,不好意思。
bvtc_liguoyuan 2007-12-13
  • 打赏
  • 举报
回复
return false;
yanniu008 2007-12-13
  • 打赏
  • 举报
回复
....
  • 打赏
  • 举报
回复
是的
ckl881003 2007-12-13
  • 打赏
  • 举报
回复
你是用复制黏贴的吧?
  • 打赏
  • 举报
回复
试了楼上几位的方法,我不明白为什么,填入数值后,仍提示内容为空。

水平较差,谢谢各位了。
ckl881003 2007-12-13
  • 打赏
  • 举报
回复
<script>       
function aaaa(){
var content = document.frmSearch.SearchFor.value;
if(content.replace(/(^\s*) ¦(\s*$)/g,"")==""){
alert("内容为空");
}
else
document.forms.frmSearch.submit();//提交放这里
}
</script>
<input type=button class="button" value="搜索" onClick="aaaa();">
homejiji 2007-12-13
  • 打赏
  • 举报
回复
给你个VBScript的方法直接加进去就可以了
onsubmit就是你的表单提交事件,用表单名称加下划线加onsubmit就能设定提交时的事件了
frmSearch_onsubmit=False是不让表单提交
这个不需要在表单中添加什么东西直接用
<SCRIPT LANGUAGE="VBScript">
Function frmSearch_onsubmit()
If Len(trim(Document.frmSearch.ctlSearchFor.value)) = 0 Then
MsgBox("内容不能为空",vbExclamation,"注意")
frmSearch_onsubmit=False
End If
end function
</SCRIPT >
yanniu008 2007-12-13
  • 打赏
  • 举报
回复
少了个name="d_text"
yanniu008 2007-12-13
  • 打赏
  • 举报
回复

<script>
function check(){
if (form1.d_text.value=="")
{
alert('请输入xxx!');
form1.d_text.focus();
return false;
}
}
</script>
<input type="button" value="submit" onclick="check()" />
  • 打赏
  • 举报
回复
谢谢各位的回复。

我试了以上几种方法,都没有实现。

我把代码贴全一点,让各位能看到明白些。

<html>
<head>
<title>单号</title>
<link REL="stylesheet" href="include/style.css" type="text/css">
</head>
<body topmargin=5 {$onload}>
{$includes}

{include_if_exists file="include/header.asp"}

<form name="frmSearch" method="GET" action="PS_WEB_VOC7_VW_list.asp">
<input type="Hidden" name="a" value="search">
<input type="Hidden" name="value" value="1">
<input type="Hidden" name="SearchFor" value="">
<input type="Hidden" name="SearchOption" value="">
<input type="Hidden" name="SearchField" value="">
</form>

<table align=center width=100% border=0 cellpadding=0 cellspacing=0>
<tr><td>

<table align=center width=100% border=0 cellpadding=4>
<tr><td>

</td></tr>

<tr><td align=right style="padding-right:15px">
{if $allow_export}
{/if}


{if $allow_export}
  
<a target="_blank" href="PS_WEB_VOC7_VW_export.asp" class="tablelinks3">输出结果</a>  
{/if}
</td></tr></table>
</td></tr>
<tr><td width=100%>
<table class="main_table2" align=center width=100% border=0 cellpadding=0 cellspacing=0>
<tr ><td align=center colspan=2>
{if $allow_search}
<table width=100% border=0 cellpadding=0 cellspacing=0 height=43px class=linedownbody>
<tr>
<td width=30 align=right class=darkshade2> </td>
<td width=22 valign=middle><img src="include/img/arrow_topmenu.gif"></td>
<td align=left valign=middle class="toplist" style="padding-top:2;padding-left:10px"">
<b>搜索 。。。。。。: </b>    
<select id="ctlSearchField">
<option value="CGD_BILLNO" {$search_CGD_BILLNO}>单号</option>
</select>
 
<select id="ctlSearchOption">
<option value="Contains" {$search_contains_option_selected}>包含</option>
</select>
    
<input type=text size=20 name="ctlSearchFor" id="ctlSearchFor" {$search_searchfor}>
 
<span class=buttonborder><input type=button class="button" value="搜索" onClick="javascript: RunSearch();"></span>


我试用了SHOWBO的代码
<script>       
function aaaa(){
var content = document.frmSearch.SearchFor.value;
if(content.replace(/(^\s*) ¦(\s*$)/g,"")==""){
alert("内容为空");
}
else
document.forms.frmSearch.submit();//提交放这里
}
</script>
<span class=buttonborder> <input type=button class="button" value="搜索" onClick="aaaa();"> </span>


但当输入了值后,仍提示“内容为空”

谢谢各位。
Atai-Lu 2007-12-13
  • 打赏
  • 举报
回复
function RunSearch(){
var keyword=document.getElementById('ctlSearchFor').value;
if(keyword==null||keyword=""){
alert("字符过短...");
return false;
}
return true;
}
Go 旅城通票 2007-12-13
  • 打赏
  • 举报
回复
<script>       
function aaaa(){
var content = document.frmSearch.SearchFor.value;
if(content.replace(/(^\s*) ¦(\s*$)/g,"")==""){
alert("内容为空");
}
else
document.forms.frmSearch.submit();//提交放这里
}
</script>
<span class=buttonborder> <input type=button class="button" value="搜索" onClick="aaaa();"> </span>
beyonal 2007-12-13
  • 打赏
  • 举报
回复
如果你想让他不继续执行,在响应方法的时间返回false就可以了。当你返回false事件就不再继续执行了
比如:
function checkInput()
{
if( 内容为空 )
{
return false;
}
else
{
return true;
}
}
<input type="button" onclick="return checkInput()">
liulang457 2007-12-13
  • 打赏
  • 举报
回复
用js
<script type="text/javascript">
<!--
function check()
{
if(document.frmSearch.ctlSearchFor.value.length == 0)
{
alert("内容不能空!");
document.frmSearch.ctlSearchFor.focus();
return false;
}
}
//-->
</script>

表单处 form 处加上onSubmit="return check()“
<form name="frmSearch" method="GET" action="PS_WEB_VOC7_VW_list.asp" onSubmit="return check()">
加载更多回复(1)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧