/    Sign up×
Community /Pin to ProfileBookmark

How to check if the textbox is empty?

in the case of checking if a textbox is empty, i know how to do it.
but in the case of having a table where you get/retrieve all the rows in the database, i dont know how to it.
Below is the sample code of what i meant. I have this table where i retrieve all the rows in the DB. each row, there is a textbox where the value is 1+1+1+1….., how will i check all these textboxes if they are empty?


_________________________________________________________

<script language=”JavaScript” type=”text/JavaScript”>
function checkField()
{
var field = document.frmCheck.[COLOR=red]TEXTBOXES IN VECTOR[/COLOR].value;
if (field == ”)
{
alert(‘Please input field!’);
return false;
}
}
</script>

<form name=”frmCheck” method=”post” action=””>
<table width=”75%” border=”1″>
<%

int x = 0;

int count = 1;
while(x < vVector.size())
{
%>

<tr>
<td>&nbsp;</td>
<td>&nbsp;<input name=”<%=count%>” type=”text” id=”<%=count%>”></td>
<%
x = x + 3;
count = count + 1;
}
%>
</tr>
</table>
</form>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 13.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

fieldset {float:left; padding:1ex}

label {display:block; text-align:right}

fieldset div {text-align:center}

-->

</style>

<script type="text/javascript">

<!--

function require (f) {

var e, i;

for (i=0; e=f.elements[i]; i++) {if (e.type == 'text' && !/S/.test(e.value)) {alert(document.getElementById ? ['Field ', e.previousSibling.data, 'is required.'].join('') : 'All fields are required'); e.focus(); return false}}

}

// -->

</script>



</head>

<body>

<form action="someScript.pl" onsubmit="return require(this)">

<fieldset>

<legend>Example</legend>

<label>A <input type="text"></label>

<label>B <input type="text"></label>

<label>C <input type="text"></label>

<label>D <input type="text"></label>

<label>E <input type="text"></label>

<label>F <input type="text"></label>

<div><button type="submit">Submit</button></div>

</fieldset>

</form>

</body>

</html>



[/font]
Copy linkTweet thisAlerts:
@kblazeauthorAug 13.2004 — Charles: what i mean is i have different textboxes with different names. let's say i have 5 txtboxes,

<%

int x = 1;

while(x <= 5)

{

%><input name="<%=x%>" type="text" id="<%=x%>"><%

x = x + 1;

}

%>

my five txtboxes have the value of:

txtBox1: 1

txtBox2: 2

txtBox3: 3

txtBox4: 4

txtBox5: 5
Copy linkTweet thisAlerts:
@CharlesAug 13.2004 — My example simply steps through every form control in the form, and if it is a check box then it is evaluated. It doesn't care how many text boxes you have or whether or not they have names.
Copy linkTweet thisAlerts:
@kblazeauthorAug 13.2004 — yahoooo.... it now works....

thanks Charles!!! thanks thanks! ?
×

Success!

Help @kblaze spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...