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!

document.write form validation of Enter Key

Status
Not open for further replies.

xencade

MIS
Jul 16, 2002
10
US
I need a script that is solely written as a .js file. It needs to use document.write statements. Could someone could provide me with a simple example that does the following:

Any form name, as a button type.
If the cursor is a active in the input field, the enter key needs to be checked and execute a function within the same .js file.

I can get the button to work, but hitting enter makes the page just refresh...
 
This js file is simply being referenced by a html file as a script src tag. The form at the bottom of this js file will load. The enter zip section is the section I need an enter key validated in addition to pressing the GO button.

_________


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="
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; onsubmit=\&quot;GO()\&quot;>&quot;);
document.write(&quot;<input type=\&quot;submit\&quot; value=\&quot;GO\&quot; class=\&quot;fhSmallform\&quot; onClick=\&quot;GO()\&quot; onsubmit=\&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;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top