Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
My first JavaScript, got a question?
Old 12-09-2004, 01:20 AM My first JavaScript, got a question?
Experienced Talker

Posts: 45
Trades: 0
Okay friends,

I've put together (well at least made an attempt) my very first JavaScript, and it's not working. I'm reading the JavaScript Bible, but I'm still confused.

You can view it (not working), at:
http://www.jacobjacobi.com/starch/files/index.html

----------------------------------------------------------------------------------------

Here's the bottom line. I've created a small zip code checker on my home page that will tell customers if service is available in their zip code. Immediately to the right of the zip code checker box, text will populate (but it doesn't) indicating whether service is available or not. So I can't figure out where I went wrong? I'm getting JavaScript error on line 3? Anybody have an idea what I did wrong?

Here's my script:

<script type="text/javascript">
<!--
function checkZip()
var zipField = document.getElementID("zip").value;
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";

if zipField == zipCode {
document.getElementById('zipResult').innerHTML = 'Great news! We service your zip code. Get started
and <a href="schedule_pickup.html">schedule a pick-up</a>.';
}
else {
document.getElementById('zipResult').innerHTML = '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.';
}
// -->
</script>

---------------------------------------------------------------------------

Here's my HTML for the header:

<script type="text/javascript" language="Javascript1.2" src="checkzip.js"></script>

--------------------------------------------------------------------------

Here's my HTML for the form:

<form><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="38%"><table width="115" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="114" valign="middle" background="../images/zipcheck2.gif">
<table width="105" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td align="center"><input name="zip" type="text" id="zip" size="5" maxlength="5"></td>
<td align="center"><a href="#"><img src="../images/check.gif" width="36" height="12" border="0" type="submit" onClick="checkzip()"></a></td>
</tr>

</table></td>
</tr>
</table>
</td>
<td width="62%" valign="top" id="zipResult"></td>
</tr>
</table></form>
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-09-2004, 04:18 AM
starsunited's Avatar
Extreme Talker

Posts: 211
Location: Singapore
Trades: 0
i dun knoe much abt java script but u could go to this website to search for java scripts that can do what u intend to do

http://www.javascriptsource.ccom
__________________

Please login or register to view this content. Registration is FREE
starsunited is offline
Reply With Quote
View Public Profile
 
Old 12-09-2004, 10:11 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
Trades: 0
Hey plane,

Heres your code working - I will try to bold face everything I changed so you can see what I did.

<script type="text/javascript">
<!--
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 = 'Great news! We service your zip code. Get started and <a href="schedule_pickup.html">schedule a pick-up</a>.';
break;
} else {
document.getElementById('zipResult').innerHTML = '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.';
}
}
}
// -->
</script>

<form name="zipcode">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="38%"><table width="115" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="114" valign="middle" background="../images/zipcheck2.gif">
<table width="105" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td align="center"><input name="zip" type="text" id="zip" size="5" maxlength="5"></td>
<td align="center"><a href="#"><img src="../images/check.gif" width="36" height="12" border="0" type="submit" onClick="checkZip()"></a></td>
</tr>

</table></td>
</tr>
</table>
</td>
<td width="62%" valign="top" id="zipResult"></td>
</tr>
</table></form>
__________________

Please login or register to view this content. Registration is FREE
- 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 12-10-2004, 02:10 PM
Experienced Talker

Posts: 45
Trades: 0
Awesome! But, I updated all my code but still having a problem?

http://www.jacobjacobi.com/starch/files/index.html

Any ideas what's up?


Thanks
Jacob
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
Old 12-10-2004, 06:12 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
Trades: 0
Hey plane,

Are you having problems with the code I gave you or with a new one? if its a new one can you please post
__________________

Please login or register to view this content. Registration is FREE
- 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 12-10-2004, 06:36 PM
Experienced Talker

Posts: 45
Trades: 0
Hey AC,

Yeah, I'm having problems with the one you gave me.

Jacob
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
Old 12-10-2004, 10:14 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
Trades: 0
Hey,

Okay, What kind of error are you recieving?

What browser are you using as well?
__________________

Please login or register to view this content. Registration is FREE
- 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 12-11-2004, 02:42 AM
Experienced Talker

Posts: 45
Trades: 0
Description: Object expected
Source: http://www.jacobjacobi.com/starch/files/index.html
Line:69
Char: 1
Error: Object expected
Code: 0
URL: http://www.jacobjacobi.com/starch/files.index.html
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
Old 12-11-2004, 04:00 AM
Experienced Talker

Posts: 45
Trades: 0
Also, I'm using IE 6.0
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
Old 12-13-2004, 11:00 AM
Experienced Talker

Posts: 45
Trades: 0
I also checked my settings, and I do have javascript enabled.
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
Old 12-13-2004, 12:45 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
Trades: 0
Okay,

For testing reasons try tacking the code out of the .js file and placeing it directly into the page. See what shows up then.
__________________

Please login or register to view this content. Registration is FREE
- 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 12-13-2004, 08:04 PM
WebcyteDesign's Avatar
Registered User

Posts: 159
Location: Hamilton
Trades: 0
your using the <script> tag in an external .js file. Remove the <script> and </script> tags and I believe it should work fine.
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Old 12-13-2004, 08:05 PM
WebcyteDesign's Avatar
Registered User

Posts: 159
Location: Hamilton
Trades: 0
P.S. Firefox is great for debugging javascript.
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Old 12-16-2004, 10:48 AM
Experienced Talker

Posts: 45
Trades: 0
Hey that worked! How do I get the 'zip' field to accept the enter command to run that script, without actually having to manually move your mouse to click the check button? Basically I would like for someone to be able to either click the check button or just hit enter.
planeboy7e7 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to My first JavaScript, got a question?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37879 seconds with 12 queries