/    Sign up×
Community /Pin to ProfileBookmark

Changing form input styles – script problem

I’m no Javascript expert, but tried to write a script to change my contact form’s inputs when the user gives it focus. The problem is that it doesn’t work. However I can get it to work if I replace ‘input’ with the form inputs id. So what I need is how to make ‘input’ be universal to the form. Below is the html and JS:

[code=php]
function on(input) {
v = document.getElementById( “contact” );
v.input.style.background = ‘#FFF’;
v.input.style.border = ‘1px solid #9A9A9A’;
}
function off(input) {
v = document.getElementById( “contact” );
v.input.style.background = ‘#F7F7F7’;
v.input.style.border = ‘1px solid #E0DFE3’;
}
[/code]

<form action=”./fghfgh.php” method=”post” id=”contact”>
<input type=”text” id=”name” name=”name” onfocus=”on(this);” onblur=”off(this);” class=”contactfield” />

etc………..

Thanks for your time.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 27.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

.contactfield-on {

border:1px solid #9A9A9A;

background-color:#FFF;

}

.contactfield-off {

border:1px solid #E0DFE3;

background-color:#F7F7F7;

}

-->

</style>

</head>

<body>

<form action="some-script.pl">

<fieldset>

<input type="text" onfocus="this.className = 'contactfield-on'" onblur="this.className = 'contactfield-off'">

</fieldset>

</form>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@richiebmanauthorNov 27.2004 — Cheers Charles, works like a dream.

R ?
×

Success!

Help @richiebman 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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