/    Sign up×
Community /Pin to ProfileBookmark

enter key not activating script

I have a script on this page

[url]http://www.jacobjacobi.com/starch/files/index.html[/url]

There is a “zip code locator” script that I use so when someone enters a zip code it will let you know if service is available in that area. However, the script only activates if you click the “Check” button, and I also want it to work when the enter button is clicked. Any ideas on what I need to change?

Here is the script:

// JavaScript Document
function checkZip(){

var zipField = document.zipcode.zip.value;
//I gave the form a name “zipcode”
var zipCode = new Array(23)
zipCode[0] = “30080”;
zipCode[1] = “30305”;
zipCode[2] = “30306”;
zipCode[3] = “30308”;
zipCode[4] = “30309”;
zipCode[5] = “30312”;
zipCode[6] = “30318”;
zipCode[7] = “30324”;
zipCode[8] = “30325”;
zipCode[9] = “30326”;
zipCode[10] = “30327”;
zipCode[11] = “30332”;
zipCode[12] = “30333”;
zipCode[13] = “30339”;
zipCode[14] = “30342”;
zipCode[15] = “30347”;
zipCode[16] = “30355”;
zipCode[17] = “30357”;
zipCode[18] = “30361”;
zipCode[19] = “30379”;
zipCode[20] = “31106”;
zipCode[21] = “31107”;
zipCode[22] = “31126”;

for(i=0;i<zipCode.length;i++){
if (zipField == zipCode[i]) {

//I added a for loop to run through the zipCode Array

document.getElementById(‘zipResult’).innerHTML = ‘<span class=”copy”>Great news! We service your zip code. Get started and <a href=”schedule_pickup.html”>schedule a pick-up</a>.</span>’;
break;
} else {
document.getElementById(‘zipResult’).innerHTML = ‘<span class=”copySmall”>Unfortunately we do not service your zip code at this time. However join our <a href=”contact_us.html”>mailing list</a>, and we will let you know as soon as service becomes available in your area.</span>’;
}
}
}

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@7studJan 20.2005 — I also want it to work when the enter button is clicked[/quote]

Hitting Enter [i][b][color="red"]submits[/color][/b][/i] the form. Hint, hint.
Copy linkTweet thisAlerts:
@planeboy747authorJan 20.2005 — well that seems obvious, but if you had tried the form you would have noticed it didn't work when you hit enter ?

so I think something else has to be changed?
Copy linkTweet thisAlerts:
@Willy_DuittJan 20.2005 — [i]Originally posted by planeboy747 [/i]

[B]well that seems obvious, but if you had tried the form you would have noticed it didn't work when you hit enter ?



so I think something else has to be changed? [/B]
[/QUOTE]


If it was so obvious you would know that you need an input type=submit or input type=image ([i]which acts the same as input type=submit[/i]) in order to submit the form thru the enter key...

An anchor is not an input and it is what is preventing your form from submitting properly... Hint, Hint... fix that and it will work as intended...

.....Willy
Copy linkTweet thisAlerts:
@johneboyJan 20.2005 — <i>
</i>&lt;form onsubmit="checkZip()"&gt;
&lt;input name="zip" type="text" id="zip" size="5" maxlength="5"&gt;&lt;/td&gt;
&lt;td align="center"&gt;
&lt;img src="../images/check.gif" width="36" height="12" border="0" type="submit" onClick="checkZip()"&gt;
&lt;/form&gt;
×

Success!

Help @planeboy747 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...