Results 1 to 3 of 3

Thread: Identifying the Form element?

  1. #1
    Join Date
    Apr 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow 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..

  2. #2
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    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

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Your syntax is invalid, and targ will always be undefined (even the setting of it will cause an error except in IE).
    Code:
      <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">&nbsp;</p>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •