Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    LZS
    LZS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question check for null textfield when submitting a form

    hi..i need to do a check if the user didn't enter anything in the textfield as he submits a form.i was told to do it using javascript
    with the pop up message of which textfield is null.what is the code or function to do this?can anyone help?thanks.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    do you want to check one form field, or multiple fields? and can we see the code for the form? that would help.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    LZS
    LZS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i need to do multiple checks in multiple mandatory textfields,
    previously i did the checks in the perl program after this page,
    but i was told it will save some processing time if i could simply check for null values before submission.i didn't know how to do it in JS.how you can guide me.

    #####this is my html page which i print in perl########
    print "Content-type: text/html\n\n";

    print"<form name=\"form1\" method=\"post\" action=\"/cgi-bin/main.pl\">\n";
    print"<div align=\"right\">Request Date : $changedateformat\n";
    print"<div align=\"center\"> \n";

    print"<p align=\"left\"><u>Organisation Details</u></p>\n";
    print"<table width=\"100%\" border=\"1\" height=\"30\">\n";
    print"<tr>\n";
    print"<td width=\"40%\" height=\"15\"><font color=\"yellow\">*</font>Organisation:\n";
    print"<select name=\"org\">\n";
    foreach $value (@list_of_orgcodes)
    { print "<option value=\"$value\">$value\n"; }
    print"</select>";
    print"</td>";

    print"<td width=\"80%\" height=\"15\"><font color=\"yellow\">*</font>Site:\n";
    # print"<select name=\"site\">\n";
    print "<select name=\"schools\">\n";
    foreach $value (@list_of_schools)
    { print "<option value=\"$value\">$value\n"; }
    print"</select>\n";
    print"</td>\n";
    print"</tr>\n";

    print"</table>\n";
    print"<p>&nbsp;</p>\n";
    print"<p align=\"left\"><u>User Details </u></p>\n";
    print"<table width=\"100%\" border=\"1\" align=\"center\">\n";
    print"<tr> \n";
    print"<td width=\"16%\"><font color=\"yellow\">*</font>First Name:</td>\n";
    print"<td width=\"34%\"> \n";
    print"<input type=\"text\" name=\"fn\" maxlength=\"50\">\n";
    print"</td>\n";
    print"<td width=\"11%\"><font color=\"yellow\">*</font>Last Name:</td>\n";
    print"<td width=\"39%\"> \n";
    print"<input type=\"text\" name=\"ln\" maxlength=\"50\">\n";
    print"</td>\n";
    print"</tr>\n";
    print"<tr> \n";
    print"<td width=\"16%\">Designation:</td>\n";
    print"<td width=\"34%\"> \n";
    print"<input type=\"text\" name=\"design\" value=\"Teacher\" maxlength=\"70\">\n";
    print"</td>\n";
    print"<td width=\"11%\">Eff Date:<br><font size=1>(YYYY-MM-DD)</font></td>\n";
    print"<td width=\"39%\">\n";
    print"<input type=\"text\" name=\"effDate\" value=\"$Eff_Date\">\n";#sysdate +1
    print"</td>\n";
    print"</tr>\n";
    print"<tr>\n";
    print"<td width=\"16%\"><font color=\"yellow\">*</font>NRIC:</td>\n";
    print"<td width=\"34%\">\n";
    print"<input type=\"text\" name=\"Nric\" maxlength=\"9\">\n";
    print"</td>\n";
    print"<td width=\"16%\">Chinese Name:</td>\n";
    print"<td width=\"34%\">\n";
    print" <select name=\"select\">\n";
    print"<option value=\"Y\">Yes</option>\n";
    print" <option value=\"N\">No</option>\n";
    print" </select>\n";
    print"</td>\n";

    print"<input type=\"hidden\" name=\"reqDate\" value=\"$Req_Date\">\n";#change to sysdate
    print"</tr>\n";
    print"</table>\n";
    print"<p align=\"right\">\n";
    print"<input type=\"submit\" name=\"Submit\" value=\"Submit\">\n";
    print"<input type=\"reset\" name=\"Submit2\" value=\"Reset\">\n";
    print "<P align=\"left\"><a href=\"http://localhost:8080/checkstatus/AdminRequestType.htm\">CLICK HERE TO RETURN TO HOME PAGE</a>";
    print"</p>\n";
    print"</div>\n";
    print"</div>\n";
    print"</form>\n";

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    See if this helps:

    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    var msg = new Object();
    msg['whatever1req'] = 'Do something with whatever1.';
    msg['whatever3req'] = 'Do something with whatever3.';

    function checkEmpty(f) {
    var el , e = 0;
    while (el = f.elements[e++]) {
    if (el.name && el.name.toLowerCase().indexOf('req') != -1 &&
    el.type == 'text' && !el .value) {
    alert(msg[el.name]);
    el.focus();
    return false;
    }
    }
    return true;
    }

    </script>
    </head>
    <body>
    <form onsubmit="return checkEmpty(this)">
    whatever1<input type="text" name="whatever1req"><br>
    whatever2<input type="text" name="whatever2"><br>
    whatever3<input type="text" name="whatever3req"><br>
    <input type="submit">
    </form>
    </body>
    </html>

    Assuming your required fields are flagged as illustrated. Key the prompt (msg) to the field name.

  • #5
    LZS
    LZS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi..thanks for your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •