Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable <RETURN> 1

Status
Not open for further replies.

TudorSmith

Programmer
Jan 14, 2002
245
GB
Hi Folks

I have a page which the user enters sales figures in INPUT boxes on a form.

When he's completed all the enteries, he clicks a button called "SAVE RECORD" and the entries are written to the database.

My issue is that when the user clicks <RETURN> or <ENTER> on the keyboard, the "SAVE RECORD" button is intiated and passes the data to the SAveRecord.ASP page...even if it's incomplete!

Is there any way ot diasable the Key Stroke for <ENTER> while the user enters the data, and only have it intitalized when the user clicks the button with the mouse?

Thanks

Tudor

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Your question assumes that the user would only click the "SAVE RECORD" button after completing all entries - nice idea but a dangerous assumption!!!

A better solution would be to check the validity of the data whether it's the button or one of the keys on the keyboard that trigger it.

Please provide details of your textboxes/entry fields - I'll provide a solution for you...
 
Hi,

I've stripped out most of the input boxes as they are all the same. Here are the first two, plus 4 hidden boxes to hold my stored data, plus the one SUBMIT input

Code:
<form method="POST" action="SAVESalesFigures.asp" name="form1">

<input align="right" type="text" size="12" name="P1_NCI" tabindex="1" onChange="UpdateNCI(<%=bNCI%>)" >

<input align="right" type="text" size="12" name="P1_HCS" tabindex="2" onChange="UpdateHCS(<%=bHCS%>)">

<!--Hidden values to pass into SAVERECORD page-->
<input TYPE="hidden" VALUE="<%=Request("SELECTROName")%>" NAME="RONAME">
<input TYPE="hidden" VALUE="<%=Request("SELECTSiteName")%>" NAME="SITENAME">
<input TYPE="hidden" VALUE="<%=Request("SELECTYear")%>" NAME="TRADEYEAR">
<input TYPE="hidden" VALUE="<%=Request("SELECTPeriod")%>" NAME="TRADEMONTH">

<input name="save" type="submit" value="Save Record">
</form>

I appreciate your help :)

Tudor

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Change your <FORM> tag as shown :
Code:
<form method="POST" action="SAVESalesFigures.asp" name="form1"[COLOR=red] onSubmit='return validateForm()'[/color]>

Then add the following between the <HEAD></HEAD> tags of your page :
Code:
<script language="JavaScript">
function validateForm()
{
  var formObj = document.form1;
  var _errMsg = "";
  
    // check mandatory fields
  if (formObj.P1_NCI.value == 0)
    _errMsg +="\n- First Text Box Value is Zero";
  if (formObj.P1_HCS.value == 0)
    _errMsg +="\n- Second Text Box Value is Zero";

  if (_errMsg == "")
  {
	return true;
  }
  else
  {
    _errMsg = "There was an error with the form. You need to address the following fields:\n" + _errMsg + "\n\nPlease correct any problems and try again";
    alert(_errMsg);
    return false;
  }
}
</script>
This assumes that the text boxes are expecting numeric entries. If either (or both) of them are blank or contain zeros, a dialog obx will be generated stating where the error is.
If your text boxes are taking text entries, you can check for zero-length entries by replacing the value == 0 with length == 0.
 
Matty

I have to wait until I get back to work tomorrow to test this out (IIS doesn't want to work on my XP machine here at home!) but just looking at the logic, I know it's going to work...and I can apply it to the other two forms that use the same funcitonality.

Many thanks

Tudor

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top