/    Sign up×
Community /Pin to ProfileBookmark

So I have this huge code that I’m using in a Make Model Year Drop down at my site: [url]http://autodiyonline.com/[/url]

I was wondering first of all how can move the code from the html document into a .js and use the import function, and second how can I condense the code so that it doesn’t take up so much space.

If you look at the source of my page you can see there are 2 scripts used for the drops downs…

<script language=”javascript” type=”text/javascript”>
function dropdownlist(listindex)
{

}

and

<script language=”javascript” type=”text/javascript”>
function dropdownlistsub(listindex)
{

}

I would like to know if I can combine these into 1 .js file and import it to the page. Sorry that I am asking these noob questions but I don’t deal much with JavaScript so I really have no clue what I’m doing. I was lucky enough to modify the original JavaScript file in order to get my Drop down lists working.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeMar 11.2011 — To answer your first question, you can put both functions into a .js file (without the <script></script> tags) and reference the .js file like so:

<script type="text/javascript" src="/path/to/filename.js"></script>

^_^
Copy linkTweet thisAlerts:
@Big_O_1_Mar 11.2011 — Try this tool for compressing your javascript:

http://www.minifyjavascript.com/
Copy linkTweet thisAlerts:
@webmasterbenauthorMar 12.2011 — Thanks for the replies guy. I got the .js file working as an import. I tried using the site to condense the JavaScript but it only could by 5%. Oh well, I guess 5% is better than nothing. Thanks again guys, I appreciate it.
×

Success!

Help @webmasterben 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.5,
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,
)...