/    Sign up×
Community /Pin to ProfileBookmark

Creating Form attributes

Is it possible to create form attributes using javascript?

There is a form tag <form id=”Form1″ method=”post” runat=”server”>
I want to be able to add/remove an attribute to it using javascript. Specifically “onkeydown”. So the javascript should cause the form tag to be <form id=”Form1″ method=”post” runat=”server” onkeydown=”texttexttext”>
and then also be able to remove that onkeydown attribute.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisAug 10.2006 — <i>
</i>// enable keydown event
oldKeyDown = document.getElementById("Form1").onkeydown;
document.getElementById("Form1").onkeydown = function () {alert("Hey, get off the keys!"); return false;}
...
// disable keydown event
document.getElementById("Form1").onkeydown = oldKeyDown;
Copy linkTweet thisAlerts:
@NatdripAug 10.2006 — [CODE][SIZE=3]<html>
<head>
<script language="javascript">
function attibuteschanger(){
document.getElementById('Form1').onmouseover=null;
}

</script>

</head>
<body>

<form id="Form1" method="post" runat="server" onMouseOver="alert('bob')">
hello
</form>

<a href="" onClick="attibuteschanger(); return false;">change atts</a>


</body>
</html>[/SIZE][/CODE]


here is another example it changes the onmouseover to null
Copy linkTweet thisAlerts:
@btisdabombauthorAug 10.2006 — I have the remove attribute part working. But I can't seem to get the add attribute to work.

What I have for the add is...

document.getElementById("Form1").onkeydown = KeyDownHandler(btnSave);

KeyDownHandler is the function I want to call whe the onkeydown event happens. It passes the name of a button into it. When I use the code above I get an error that says "btnSave is not defined". Well it is a button on the page so I don't know how it isn't defined. Is there something I'm missing?
Copy linkTweet thisAlerts:
@gil_davisAug 10.2006 — Is there something I'm missing?[/QUOTE]
You can't pass vars like that in an event handler. You have to create a function like we showed you.
Copy linkTweet thisAlerts:
@btisdabombauthorAug 10.2006 — Thanks for your help!!! I have it working now.
×

Success!

Help @btisdabomb 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.20,
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,
)...