View Full Version : Identifying the Form element?
hi all,
in a web page there are two <form>'s ,how to identify the form that i focus on it's own element.That is if i click on the form2 elements then it will display the name of the secnd form.if i focus in first form element get the form1 name.how can i achieve this.
can any one help me..
riptide
05-21-2007, 02:55 PM
try something like this
var o =document.getElementById("one1")
var t=document.getElementById("two2")
var e=e? e : window.event;
var targ=e.target? e.target : e.srcElement;
function show{
if (if (target==o ){document.write("forumone")}
else if(if (target==t ){document.write("forumtwo")
onclick="show()"
add ids to both forums;one1 and two2 and put the onclick in them
Your syntax is invalid, and targ will always be undefined (even the setting of it will cause an error except in IE).
<script type="text/javascript">
function setCurrentForm() {
document.getElementById("currentFormName").firstChild.nodeValue = (this.form.name || this.form.id);
}
onload = function() {
for(var i = 0, f = document.forms; i < f.length; ++i)
for(var j = 0, e = f[i].elements; j < e.length; ++j)
e[j].onfocus = setCurrentForm();
};
</script>
</head>
<body>
<p id="currentFormName"> </p>
Powered by vBulletin® Version 4.2.2 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.