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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When press return, don't want to submit

Status
Not open for further replies.

stewartwebb

Programmer
Jan 6, 2004
92
GB
Hi all,

I have a problem with my page I can't solve.
Basically I have a text box and 'onKeyUp' I perform a function which checks 'if(window.event.keyCode == 13)' if it does it performs the funtion below.

Code:
function funcFind()
{
checkForSpaces(document.form1.FIND.value)
if(fieldHasSpaces == "Y")
    {message.innerHTML = "";
	message.innerHTML = "You must enter a search value";
	alert("You must enter a search value");
	funcSetFocus();
	return;
	}
	
document.form1.entpoint.value = "Find";
document.form1.submit();
}

The problem is that when there is no value in the text box and I click return, 'fieldHasSpaces' (from the function above) does == 'Y'. Yet somehow the alert in this function does not display and the page submits. The annoying thing is I put an alert just before the 'document.form1.submit();' which was also not being displayed so i'm thinking the submit maybe caused by something else on the page. There is only 1 text box on the page.
Has anyone else come across this problem?

Thanks
Stewart
 
Where are you setting "fieldHasSpaces"? I can't see it defined anywhere. Also perhaps giving us the contents of the "checkForSpaces" function might be useful if it's part of the equation.

Or possibly the error is on line 17, character 6?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

The checkForSpaces function is in the global javascript file and has been used on loads of pages and never had a problem before. The fieldHasSpaces is declared in the global javavscript file aswell.
I don't believe it is anything to do with the checkForSpaces function as I put an alert before this call and this alert doesn't display either, it seems it doesn't even get into the funcFind() function. I'm lost on whats happening. Here's the whole page if it helps.

Code:
<html>
<head>
<title>A.M.L. General Enquiries</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" media="print">
<!--
td { font-family: monospace; font-size: 8pt; color: #000000 }
-->
</style>
<link rel="stylesheet" href="../amlgcsglobal.css" type="text/css" media="screen">
<script language="JavaScript" src="../amlgcs_scripts.js" type="text/JavaScript">
<!--
//-->
</script>
<script language="JavaScript">
<!--
var inputINDS;
var inputSTATE;

function goTO(pageName,menuheading)
{
var homeURL;
var pageINDS = window.document.form1.INDS.value;
var pageSTATE = window.document.form1.STATEKEY.value;

	if (pageName == "Home")
	{
	homeURL = "/cgi-bin/rts32?CNTL0102.int+K+A%3DOut+";
	window.location=homeURL + pageSTATE + "+" + pageINDS;
	}	
}

function funcSetFocus()
{
document.form1.FIND.focus();
}

function funcCheckKey()
{
if(window.event.keyCode == 13)
    {funcFind();
	}
}

function funcFind()
{
checkForSpaces(document.form1.FIND.value)
if(fieldHasSpaces == "Y")
    {message.innerHTML = "";
	message.innerHTML = "You must enter a search value";
	alert("You must enter a search value");
	funcSetFocus();
	return;
	}
	
document.form1.entpoint.value = "Find";
document.form1.submit();
}

</script>
</head>
<body onLoad="funcSetFocus(); setUpPage();" onUnload="stoptimer();">
<form method="post" action="/cgi-bin/rts32?AMSA6002.int" name="form1">
<table id="header" class="headfootTable" cellpadding="0" cellspacing="0">
  <tr>
    <td height="20" width="31%" rowspan="3" valign="middle"><img src="/gfx/amllogo2.jpg" width="300" height="52"></td>
    <td width="42%" align="center" class="screenTitleSmall">&nbsp;</td>
    <td width="26%" align="right" class="screenTitleSmall"><!--CGIX DATAFIELD=COYNAME--></td>
    <td width="1%" align="right">&nbsp;</td>
  </tr>
  <tr>
    <td height="20" align="center" valign="middle" class="screenTitleBig">User ID Enquiry </td>
    <td align="right" id="DEMOtext" class="demomessage"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="20" align="center">&nbsp;</td>
    <td align="right" class="screenTitleSmall"><a href="javascript:printContent();">PRINT</a>&nbsp;&nbsp;&nbsp;<a href="javascript:goTO('Home');">HOME</a>&nbsp;&nbsp;&nbsp;<a href="javascript:goTO('Logoff');">LOG OFF</a></td>
    <td align="right">&nbsp;</td>
  </tr>
</table>
<table class="nestedTable" cellpadding="0" cellspacing="0">
    <tr> 
      <td height="20" valign="top"> 
        <table class="nestedTable" cellpadding="0" cellspacing="0">
          <tr> 
            <td width="1%">&nbsp;</td>
            <td width="98%"> 
						   <table class="nestedTable" cellpadding="0" cellspacing="0">
                            <tr> 
                              <td width="97%" height="15" id="message" class="message">
                                  <!--CGIX DATAFIELD=MESSAGE--></td>
                            </tr>
                            <tr> 
                              <td align="right"> 
                                      <table cellpadding="0" cellspacing="0" class="nestedTable" border="1">
                                        <tr> 
                                          <td valign="top" width="86%"> 
                                            <table class="nestedTable" width="100%" cellpadding="2" cellspacing="0">
                                              <tr> 
                                                <td width="24%" height="30" align="right">Search For:&nbsp;&nbsp;</td>
                                                <td width="61%" ><input type="text" name="FIND" maxlength="28" size="28" value="<!--CGIX DATAFIELD=FIND-->" onDblClick="this.value='';" onKeyUp="funcCheckKey();">&nbsp;&nbsp;
                                                <input type="button" name="findbutton" value="Find" tabindex="2" onClick="funcFind();" onDblClick="funcFind();" class="smallButton" style="width:80px;";></td>
                                                <td width="15%" align="left">&nbsp;</td>
                                              </tr>
											  <tr> 
                                                <td height="30" align="right"></td>
                                                <td></td>
                                                <td align="left"></td>
                                              </tr>
                                              <tr> 
                                                <td colspan="3" align="center" valign="top">
                                                <table  width="100%" cellpadding="0" cellspacing="0" class="nestedTable">
                                                    <tr> 
                                                      <td width="11%" class="listHeadingLeft">User ID</td>
                                                      <td width="15%" class="listHeadingMid">Company</td>
                                                      <td width="33%" align="left" class="listHeadingMid">User Name</td>
                                                      <td width="10%" class="listHeadingMid">CDS ID</td>
                                                      <td width="15%" align="left" class="listHeadingMid">Set Up Date</td>
                                                      <td width="16%" class="listHeadingRight">Last Used Date</td>
                                                    </tr>
                                                      <!--CGIX ROWS-->
                                                      <tr> 
                                                        <td width="11%" height="20" valign="middle"><!--CGIX DATAFIELD=USER_ID--></td>
                                                        <td width="15%" valign="middle"><!--CGIX DATAFIELD=COMPANY-->                                                        </td>
                                                        <td width="33%" align="left" valign="middle"> <!--CGIX DATAFIELD=USER_NAME-->                                                        </td>
                                                        <td width="10%" valign="middle"> <!--CGIX DATAFIELD=CDS_ID-->                                                        </td>
                                                        <td width="15%" align="left" valign="middle"> <!--CGIX DATAFIELD=SETUP_DATE-->                                                        </td>
                                                        <td width="16%" valign="middle"><!--CGIX DATAFIELD=LASTUSED_DATE--></td>
                                                      </tr>
                                                      <!--CGIX /ROWS-->
                                                  </table>												
												  </td>
                                              </tr>
                                            </table>
											</td>
                                        </tr>
                                      </table>
							  </td>
                             </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
            <td width="1%">&nbsp;</td>
          </tr>
		  <tr>
            <td height="4"></td>
            <td></td>
            <td>
      </td>
    </tr>
  </table>
  <input type="hidden" name="entpoint">
  <input type="hidden" name="STATEKEY" value="<!--CGIX DATAFIELD=STATEKEY-->">
  <input type="hidden" name="INDS" value="<!--CGIX DATAFIELD=INDS-->">
  <input type="hidden" name="DEMO_SYSTEM" value="<!--CGIX DATAFIELD=DEMO_SYSTEM-->">
</form>
</body>
</html>

Thanks

Stewart.
 
Maybe it's so much more obvious to me than to you... So I'll try and be patient!

You ask a question saying that the "fieldHasSpaces" variable holds a "Y" even when a certain field is blank, but do not ever show us where it's populated.

I tell you this, and you tell us that it is "in a global"... but [!]still[/!] don't show us how it is being populated.

Are we meant to guess this? Given that it is most likely whatever is setting this variable is where the problem lies, don't you think it would be good for us to see this piece of code (which you've still not given us)?

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top