Changing objects in webform with javascript in js file

Hi,

I have a webform with different html objects for example a textbox:
 
<input type="text" name="cardholder_name" size="20" value=""
                id="auth_cardholder_name" />

Open in new window


and a button
 <button type="submit" id="auth_0"
            value="Validate payment" onclick="void(0);">
            Validate payment</button>

Open in new window


I would like to be able to reach these objects from a js file and change their styles (for example font and color of the text etc.)

I've always done this from the page itself like this for example
document.getElementById("auth_cardno").className = "box";

Open in new window


But how can I achieve tthe same from a separate js file and activate it on page load?

Thanks for help!

Peter
Peter NordbergIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duy PhamFreelance IT ConsultantCommented:
You can do the same in your separate js file to change style (or className of your elements). And use window.onload to activate it on page load:

// assume this your js file:  your-scripts.js
...
window.onload = function() {
    // change styles of your elements here
    document.getElementById("auth_cardholder_name").className = "box";
    document.getElementById("auth_0").className = "button-class";
    ...
};
...

Open in new window


And include that separate script file after your body end tag

<html>
    <head>...</head>
    <body>...</body>
    <script type="text/javascript" src="your-scripts.js"></script>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.