Jump to content

jQuery - need alert when empty form submitted


cyber-guys

Recommended Posts

I have a link that opens a small form asking for an account code - when the user enters a valid account code it opens another page whose url is mysite.com/'account code'/menu.htm The folder named 'account code' is a protected folder and the user will then log in with a userid/passwordIf the user does not enter anything I would like an alert 'Please enter something in the box" and if they enter a wrong code an alert that says 'Wrong code, please try again!'upon opening the menu page, the account code form closes itselfThe problem I'm having is with the nothing entered alert - if nothing is entered the redirect goes to mysite.com/menu.htm which gives a 404 and proceeds to close the form - entering a wrong code gives the correct alert and keeps the form open like I want it to. This is the code in the form:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>Enter Account Code</TITLE><META content="text/html; charset=UTF-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 8.00.6001.19046"><STYLE type=text/css>BODY { FONT-FAMILY: verdana, arial, sans-serif}</STYLE><div id="some_div" style="display:none"></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script><script type="text/javascript">$(document).ready(function(){ $("#some_div").ajaxComplete(function(e, xhr) { if(xhr.status == '404'){ alert("Wrong code, please try again!"); }else{ open_window(); } }); });function send_to_url(){ $('#some_div').load($("#input").val()+"/index.htm"); if(input_field == ''){ alert("Please enter something in the box!"); return false }}function open_window(){ window.open($("#input").val()+"/menu.htm"); window.close();}</script><div id="some_div" style="display:none"></div><Font face="verdana,arial" size=2 color="#000000"><center>Please Enter Account Code<BR><input type="text" name="input" id="input"><br><input type="button" name="buttton" value="Submit" onClick="send_to_url()"> </BODY></HTML>You can visit the page at http://www.windfieldalloy.com/login.htm - code=PartnerDemo, user=guest, pass=guestI'm sure the problem is syntax but I'm totally new at this jQuery/Ajax stuffThanks in advance for any help,Jim

Link to comment
Share on other sites

to check for an empty string, use ""I think it would be better to test the value(s) of the input element(s) for an empty string on submit, if it's not empty, then test the request by submitting the code or credentials, and if it comes back OK, then you can do one thing, else, do something else.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...