Javascript form number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rd

    Javascript form number

    How can I get the form number by using the this command?

    document.forms[6] is the seventh form on the page

    If the seventh form looked like this:

    <form>
    <input type="button" onclick="myFunc tion(this)">
    </form>

    How can I make myFunction return the number 6?

    this.form.??


    Thanks,

    rd
  • Vjekoslav Begovic

    #2
    Re: Javascript form number

    "rd" <bewareoffifi@m yway.com> wrote in message
    news:8de4eab3.0 311182256.6ab6d 9e8@posting.goo gle.com...[color=blue]
    > How can I get the form number by using the this command?
    >
    > document.forms[6] is the seventh form on the page
    >
    > If the seventh form looked like this:
    >
    > <form>
    > <input type="button" onclick="myFunc tion(this)">
    > </form>
    >
    > How can I make myFunction return the number 6?[/color]

    onclick="return myFunction(this .form)";

    function myFunction(form ){
    var frms=document.f orms;
    for (var i=0; i<frms.length;i ++){
    if (frms[i] == form){
    return i;
    }
    }
    return null;
    }


    Comment

    • rd

      #3
      Re: Javascript form number

      Thanks!

      "Vjekoslav Begovic" <vjbegovic@inet .hr> wrote in message news:<bpfakj$ap 3$1@ls219.htnet .hr>...[color=blue]
      > "rd" <bewareoffifi@m yway.com> wrote in message
      > news:8de4eab3.0 311182256.6ab6d 9e8@posting.goo gle.com...[color=green]
      > > How can I get the form number by using the this command?
      > >
      > > document.forms[6] is the seventh form on the page
      > >
      > > If the seventh form looked like this:
      > >
      > > <form>
      > > <input type="button" onclick="myFunc tion(this)">
      > > </form>
      > >
      > > How can I make myFunction return the number 6?[/color]
      >
      > onclick="return myFunction(this .form)";
      >
      > function myFunction(form ){
      > var frms=document.f orms;
      > for (var i=0; i<frms.length;i ++){
      > if (frms[i] == form){
      > return i;
      > }
      > }
      > return null;
      > }[/color]

      Comment

      Working...