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

How to submit a form by usage of enter key

Status
Not open for further replies.

xencade

MIS
Jul 16, 2002
10
US
Could someone give me an example of using the ENTER KEY if the cursor is active in a given form field? The form I created is in a .js file within a function.

What the users want is to hit enter after they have entered the form data instead/in addition to the submit button.

Thanks!
 
In my experience with IE and NS, when a form has an actual submit button <input type=&quot;submit&quot;>, this is how the form will behave by default and you'd have to create script to PREVENT it from submitting with the enter key.

Perhaps show your code if yours isn't working this way.

======================================

if (!succeed) try();
-jeff
 
Here is the code... I've tried changing the form input to submit, but it only refreshes the page...


______________________________

document.write(&quot;</select></form></div>&quot;);
document.write(&quot;<div align=\&quot;center\&quot;><form name=\&quot;zipsearch\&quot; class=\&quot;fhSmallForm\&quot; method=\&quot;post\&quot; action=\&quot;\&quot; enctype=\&quot;multipart/form-data\&quot;>&quot;);
document.write(&quot;<font color=\&quot;#000000\&quot; class=\&quot;fhsmallfont\&quot;>Enter US Zip </font>&quot;);
document.write(&quot;<input name=\&quot;findzip\&quot; class=\&quot;fhsmallform\&quot; maxlength=\&quot;5\&quot; size=\&quot;5\&quot; TYPE=\&quot;text\&quot;>&quot;);
document.write(&quot;<input type=\&quot;button\&quot; value=\&quot;GO\&quot; class=\&quot;fhSmallform\&quot; onClick=\&quot;GO()\&quot;>&quot;);
document.write(&quot;</form></div>&quot;);
 
it actually is submitting - change the method to &quot;GET&quot; and you can see the results in the address bar.

what's processing the submitted data? is there a cgi script or something else on the server side?

======================================

if (!succeed) try();
-jeff
 
Here is the entire .js file. It is being sourced from the main css. The GO function and button work fine, but hitting enter simply refreshes the page. I tried changing the form input type to button, but it doesn't work at all.

____________________________
var weatherstate;
weatherstate='show';


function GO()
{
//Check if zipcode entered is a number
if (isNaN(document.zipsearch.findzip.value))
{
alert('Please Use Numerical Values Only');
document.zipsearch.findzip.focus();
return;
}
{
var zipcodepars = document.zipsearch.findzip.value;
// document.write(zipcodepars)
//location.href=&quot;
document.all['WeatherLayer'].style.top = document.forms['myweather'].offsetTop-20;
MM_showHideLayers('WeatherLayer','','show');
weatherstate='hide';
showhideweatherlink.innerText=weatherstate;

document.weathermagnet.src=' document.weathermagnet.parentElement.href='}}


function changeweather() {
document.weathermagnet.src='[document.myweather.weather.selectedIndex].value+'&code=1111';
document.weathermagnet.parentElement.href='[document.myweather.weather.selectedIndex].value+'&par=internal&site=magnet&code=1111&promo=english';
}

function showhideweather(overridestate) {
document.all['WeatherLayer'].style.top = document.forms['myweather'].offsetTop-20;
if (overridestate!='')
weatherstate=overridestate;
if (weatherstate=='show') {
MM_showHideLayers('WeatherLayer','','show');
weatherstate='hide'
} else {
MM_showHideLayers('WeatherLayer','','hide');
weatherstate='show'
}
changeweather();
showhideweatherlink.innerText=weatherstate;
}

document.write(&quot;<div class=fhToolsSubHeadline>&quot;);
document.write(&quot;<table border=0 cellspacing=0 cellpadding=0 width=\&quot;90%\&quot; class=fhToolsSubHeadline>&quot;);
document.write(&quot;<tr><td> Weather</td>&quot;);
document.write(&quot;<td align=right><A class=fhsmallerfont href=\&quot;#\&quot; name=showhideweatherlink onmousedown=\&quot;showhideweather('')\&quot;>show</a>&quot;);
document.write(&quot;</td></tr></table>&quot;);
document.write(&quot;</div>&quot;);
document.write(&quot;<div align=center>&quot;);
document.write(&quot;<form name=\&quot;myweather\&quot; class=\&quot;fhSmallForm\&quot;>&quot;);
document.write(&quot;  <select name=\&quot;weather\&quot; size=\&quot;1\&quot; class=\&quot;fhsmalldropdown\&quot; onfocus=\&quot;showhideweather('show')\&quot; onchange=\&quot;changeweather();\&quot;>&quot;);

document.write(&quot;<option value=\&quot;USGA0028\&quot; &quot;);
if (user.city == &quot;Atlanta&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Atlanta, GA</option>&quot;);

document.write(&quot;<option value=\&quot;USNJ0052\&quot; &quot;);
if (user.city == &quot;Boonton&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Boonton, NJ</option>&quot;);

document.write(&quot;<option value=\&quot;USKY0801\&quot; &quot;);
if (user.city == &quot;Covington&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Covington, KY</option>&quot;);

document.write(&quot;<option value=\&quot;USTX0327\&quot; &quot;);
if (user.city == &quot;Dallas&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Dallas, TX</option>&quot;);

document.write(&quot;<option value=\&quot;USOH0269\&quot; &quot;);
if (user.city == &quot;Dublin&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Dublin, OH</option>&quot;);

document.write(&quot;<option value=\&quot;USAR0189\&quot; &quot;);
if (user.city == &quot;Fayetteville&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Fayetteville, AR</option>&quot;);

document.write(&quot;<option value=\&quot;USAR0197\&quot; &quot;);
if (user.city == &quot;Fort Smith&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Fort Smith, AR</option>&quot;);

document.write(&quot;<option value=\&quot;USAR0248\&quot; &quot;);
if (user.city == &quot;Harrison&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Harrison, AR</option>&quot;);

document.write(&quot;<option value=\&quot;CAXX0216\&quot; &quot;);
if (user.city == &quot;Kelowna&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Kelowna, Canada</option>&quot;);

document.write(&quot;<option value=\&quot;USKY1079\&quot; &quot;);
if (user.city == &quot;Lexington&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Lexington, KY</option>&quot;);

document.write(&quot;<option value=\&quot;CAXX0297\&quot; &quot;);
if (user.city == &quot;Moncton&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Moncton, Canada</option>&quot;);


document.write(&quot;<option value=\&quot;USCO0323\&quot; &quot;);
if (user.city == &quot;Pueblo&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Pueblo, CO</option>&quot;);

document.write(&quot;<option value=\&quot;USAR0485\&quot; &quot;);
if (user.city == &quot;Rogers&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Rogers, AR</option>&quot;);

document.write(&quot;<option value=\&quot;NLXX0015\&quot; &quot;);
if (user.city == &quot;Rotterdam&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Rotterdam, Netherlands</option>&quot;);

document.write(&quot;<option value=\&quot;USKY1298\&quot; &quot;);
if (user.city == &quot;Russell&quot; || user.city == &quot;Bellefonte&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Russell, KY</option>&quot;);

document.write(&quot;<option value=\&quot;USCA1016\&quot; &quot;);
if (user.city == &quot;Santa Ana&quot;) document.write(&quot;selected&quot;);
document.write(&quot;>Santa Ana, CA</option>&quot;);

document.write(&quot;</select></form></div>&quot;);
document.write(&quot;<div align=\&quot;center\&quot;><form name=\&quot;zipsearch\&quot; class=\&quot;fhSmallForm\&quot; method=\&quot;post\&quot; action=\&quot;\&quot; enctype=\&quot;multipart/form-data\&quot;>&quot;);
document.write(&quot;<font color=\&quot;#000000\&quot; class=\&quot;fhsmallfont\&quot;>Enter US Zip </font>&quot;);
document.write(&quot;<input name=\&quot;findzip\&quot; class=\&quot;fhsmallform\&quot; maxlength=\&quot;5\&quot; size=\&quot;5\&quot; TYPE=\&quot;text\&quot;>&quot;);
document.write(&quot;<input type=\&quot;button\&quot; value=\&quot;GO\&quot; class=\&quot;fhSmallform\&quot; onClick=\&quot;GO()\&quot;>&quot;);
document.write(&quot;</form></div>&quot;);
document.write(&quot;<div id=\&quot;WeatherLayer\&quot; style=\&quot;background-color: #cccccc; HEIGHT: 150px; LEFT: 180px; POSITION: absolute; TOP: 47px; VISIBILITY: hidden; WIDTH: 270px; Z-INDEX: 7\&quot;>&quot;);
document.write(&quot;<div align=right>&quot;);
document.write(&quot;<a href=# onmousedown=\&quot;showhideweather('hide')\&quot;><img src=images/closebutton.gif width=10 height=10 border=0></a>&quot;);
document.write(&quot;<a name=weathermagnetlink href=\&quot; target=_blank><img name=weathermagnet border=0 vspace=3 hspace=3 width=270 height=140 SRC=\&quot;images/null.gif\&quot;></a>&quot;);


document.write(&quot;</div>&quot;);

document.write(&quot;</div>&quot;);
 
when a form submits, there must be something on the server side to process what is submitted. your &quot;action&quot; attribute of the form tag is blank, which will default to itself as the recipient of the form - but javascript alone cannot do anything with &quot;post&quot; form data. you must have server-side code to process post data.

keep your submit button as a type=&quot;submit&quot;, unless you attach an event handler like onclick=&quot;this.form.submit();&quot; to the type=&quot;button&quot; submit button. ======================================

if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top