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

Form field blanks on carriage return

Status
Not open for further replies.
May 22, 2002
63
0
0
GB
Hi,

Bit of an odd problem: I have a simple form with a text field, and next to it a 'Submit' button. When entering text into the field and pressing the carriage return button on my keyboard the text field goes blank and nothing is submitted.

It is only when I click the Submit button with the mouse cursor that the submit is actioned correctly. Can anyone suggest why this may be the case?

The code for the form is here:

print "
<p><strong><font size=\&quot;2\&quot; face=\&quot;Arial, Helvetica, sans-serif\&quot;>Please enter a search string (min 3 chars)</font></strong></p>&quot;;
print &quot;<form method=\&quot;POST\&quot;>&quot;;
print &quot;<input type\&quot;text\&quot; name=\&quot;Searchstring\&quot;</strong></font>&quot;;
print &quot; <input type=\&quot;submit\&quot; name=\&quot;searchsubmit\&quot; value=\&quot;Submit\&quot;>&quot;;
print &quot;</form><p>&quot;;


Thanks,

Anderz
 
It might be that you're not closing all your HTML tags correctly.

This line:
print &quot;<input type\&quot;text\&quot; name=\&quot;Searchstring\&quot;</strong></font>&quot;;

Appears to not have a closing &quot;>&quot; for the input element

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I've tried updating it but it still doesn't work. It seems like something else is stealing focus?

IF possible could you look at the entire page of code?...

Anders

<html>
<head>
<SCRIPT LANGUAGE=&quot;javascript&quot;>
<!--//
function openit(sURL){
newwindow=open(sURL,&quot;newwin&quot;,&quot;scrollbars=yes, toolbar=no,directories=no, menu bar=no, resizable=yes,status=no&quot;);
}
//-->
</SCRIPT>
<style type=&quot;text/css&quot;>
<!--
body{
background-attachment:fixed;
background-image:url(handsup.jpg);
background-repeat:no-repeat;
background-position:right bottom;
}
-->
</style>
<title>Viewing all by Group</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body>

<font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><strong>Please select your order by option:</strong></font><form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;/masterview.php?group=&category=&search=true&view=search&sortby=&quot;> <table width=&quot;100%&quot; border=&quot;0&quot;> <tr><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;> <select name=&quot;sortby&quot; id=&quot;sortby&quot;><option style=&quot;background-color: #CCCCaC&quot; selected value=&quot;contacts.contactcompany&quot;>Order By...</option><option style=&quot;background-color: #CCCCaC&quot; value=&quot;contacts.contactfname&quot;><strong>First Name</strong></option><option style=&quot;background-color: #CCCCaC&quot; value=&quot;contacts.contactsname&quot;><strong>Last Name</strong></option><option style=&quot;background-color: #CCCCaC&quot; value=&quot;contacts.contactcompany&quot;><strong>Company</strong></option></select></font> <input type=&quot;submit&quot; name=&quot;sortbysubmit&quot; value=&quot;Refresh&quot;></form></table><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;1&quot;><strong>Currently sorted by Company (in ascending order.)</strong></font>
<p><strong><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Please enter a search string (min 3 chars)</font></strong></p><form method=&quot;POST&quot;><input type=&quot;text&quot; name=&quot;Searchstring&quot;></strong></font> <input type=&quot;submit&quot; name=&quot;searchsubmit&quot; value=&quot;Submit&quot;></form><p><p><strong><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;><a href=&quot;body2.php?show=main&quot; target=&quot;mainFrame&quot;>Home</a></font>
<br>
</body>
</html>
 
well this is a strange problem, ie in IE if there is only one text control and a submit button hitting an &quot;enter&quot; will submit the form!!! the best way to overcome this is:
in the form tag:
<form..... onsubmit=&quot;return false&quot;>

and in the submit button:
<input type=&quot;BUTTON&quot; name&quot;b1&quot; value=&quot;Submit&quot; onclick=&quot;SubmitFrm()&quot;>

<head>
<script>
function SubmitFrm()
{
document.FormName.action=&quot;page_here&quot;
document.FormName.submit()
}
</script>
</head>

Note: this will work 99%, but if it doesnt let me know...

Known is handfull, Unknown is worldfull
 
To be honest, there are so many odd things going on in that HTML, it's hard to separate the wheat from the chaff.

You're not using <TR>...</TR> or <TD>...</TD> tags correctly.

You tend to intermix <font>...</font> tags and stylesheets. It's legal to do that, I suppose, but better to pick one or the other, and best to pick stylesheets.

You have two forms on that page, but you haven't specified which, if not both, is demonstrating the problem.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Now as soon as i click within the text field it submits automatically before i even enter something.

Do you think the form above may be affecting things?
 
Sorry my coding is terrible I know!

There are two forms the first is ok, it is the second one that is causing problems:

<font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Please enter a search string (min 3 chars)</font></strong>
</p>
<form method=&quot;POST&quot;>
<input type=&quot;text&quot; name=&quot;Searchstring&quot;></strong></font>
<input type=&quot;submit&quot; name=&quot;searchsubmit&quot; value=&quot;Submit&quot;>
</form>

Is it that i haven't specified that the action should be $PHP_SELF?
 
I have found that if I make the PHP check for a form element variable rather than a simple (!empty($Submit)) type check then it works???!!?

Weird!

Thanks for all your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top