HELP. this.form does not seem to pass value...

Discussion in 'Javascript' started by Shippy, Jul 19, 2006.

  1. Shippy

    Shippy Guest

    Please help, this is doing my head in!!!! I am sure it is something
    really simple and ovbious that I am missing but for the life of me I
    cant find where!!!

    I have this function...

    <script>
    <!--
    function update(frm) {
    var mon, mon1, form;

    form=frm;
    mon=frm.mon.value;

    alert(mon);
    }
    -->
    </script>


    and this calls it...

    <form method="post" name="sas002">
    <tr>
    <td><input name="mon" value="1" size="5"></td> <td><input name="tue"
    value="1" size="5"></td>
    <td><img src="../images/edit.gif" onClick="update(this.form)"></td>
    </tr>
    </form>

    how whenever I run this i get an undefined for the form name...

    its as if the this.form is not passing the form name through like it
    should be - any suggestions?

    need to do it like this as the form is created dynamically....
     
    Shippy, Jul 19, 2006
    #1
    1. Advertising

  2. Shippy

    Erwin Moller Guest

    Shippy wrote:

    > Please help, this is doing my head in!!!! I am sure it is something
    > really simple and ovbious that I am missing but for the life of me I
    > cant find where!!!
    >
    > I have this function...
    >
    > <script>
    > <!--
    > function update(frm) {
    > var mon, mon1, form;
    >
    > form=frm;
    > mon=frm.mon.value;
    >
    > alert(mon);
    > }
    > -->
    > </script>
    >
    >
    > and this calls it...
    >
    > <form method="post" name="sas002">
    > <tr>
    > <td><input name="mon" value="1" size="5"></td> <td><input name="tue"
    > value="1" size="5"></td>
    > <td><img src="../images/edit.gif" onClick="update(this.form)"></td>
    > </tr>
    > </form>
    >
    > how whenever I run this i get an undefined for the form name...
    >
    > its as if the this.form is not passing the form name through like it
    > should be - any suggestions?


    Excactly, and why do you say it should be passing the formname if you use
    this.form in an image?

    The keyword 'this' should only be used if you knwo WHAT it is refering to.
    eg: If you use it in an input type="text" it will reference that
    inputelement.
    If you use it in an image....

    Solution: simple give your form a name, and pass that to the function.
    From your function you can use:
    function update(formname) {
    var formref=document.forms[formname];
    var mon=formref.mon.value;
    alert(mon);
    }

    >
    > need to do it like this as the form is created dynamically....



    That is no reason to leave the names of the forms out. :)

    Good luck!

    Regards,
    Erwin Moller
     
    Erwin Moller, Jul 19, 2006
    #2
    1. Advertising

  3. Shippy

    Erwin Moller Guest

    Erwin Moller wrote:

    > Shippy wrote:
    >
    >> Please help, this is doing my head in!!!! I am sure it is something
    >> really simple and ovbious that I am missing but for the life of me I
    >> cant find where!!!
    >>
    >> I have this function...
    >>
    >> <script>
    >> <!--
    >> function update(frm) {
    >> var mon, mon1, form;
    >>
    >> form=frm;
    >> mon=frm.mon.value;
    >>
    >> alert(mon);
    >> }
    >> -->
    >> </script>
    >>
    >>
    >> and this calls it...
    >>
    >> <form method="post" name="sas002">
    >> <tr>
    >> <td><input name="mon" value="1" size="5"></td> <td><input name="tue"
    >> value="1" size="5"></td>
    >> <td><img src="../images/edit.gif" onClick="update(this.form)"></td>
    >> </tr>
    >> </form>
    >>
    >> how whenever I run this i get an undefined for the form name...
    >>
    >> its as if the this.form is not passing the form name through like it
    >> should be - any suggestions?

    >
    > Excactly, and why do you say it should be passing the formname if you use
    > this.form in an image?
    >
    > The keyword 'this' should only be used if you knwo WHAT it is refering to.
    > eg: If you use it in an input type="text" it will reference that
    > inputelement.
    > If you use it in an image....
    >
    > Solution: simple give your form a name, and pass that to the function.
    > From your function you can use:
    > function update(formname) {
    > var formref=document.forms[formname];
    > var mon=formref.mon.value;
    > alert(mon);
    > }
    >
    >>
    >> need to do it like this as the form is created dynamically....

    >
    >
    > That is no reason to leave the names of the forms out. :)


    Oops, my bad.
    You DID name the form already, so if you want to use it in your
    image-onClick-handler you can do this:
    <td><img src="../images/edit.gif" onClick="update('sas002');"></td>
     
    Erwin Moller, Jul 19, 2006
    #3
  4. Shippy

    Shippy Guest

    Your an absolute STAR - many thanks!

    completely forgot about "this." being related to that item...
    Erwin Moller wrote:

    > Shippy wrote:
    >
    > > Please help, this is doing my head in!!!! I am sure it is something
    > > really simple and ovbious that I am missing but for the life of me I
    > > cant find where!!!
    > >
    > > I have this function...
    > >
    > > <script>
    > > <!--
    > > function update(frm) {
    > > var mon, mon1, form;
    > >
    > > form=frm;
    > > mon=frm.mon.value;
    > >
    > > alert(mon);
    > > }
    > > -->
    > > </script>
    > >
    > >
    > > and this calls it...
    > >
    > > <form method="post" name="sas002">
    > > <tr>
    > > <td><input name="mon" value="1" size="5"></td> <td><input name="tue"
    > > value="1" size="5"></td>
    > > <td><img src="../images/edit.gif" onClick="update(this.form)"></td>
    > > </tr>
    > > </form>
    > >
    > > how whenever I run this i get an undefined for the form name...
    > >
    > > its as if the this.form is not passing the form name through like it
    > > should be - any suggestions?

    >
    > Excactly, and why do you say it should be passing the formname if you use
    > this.form in an image?
    >
    > The keyword 'this' should only be used if you knwo WHAT it is refering to.
    > eg: If you use it in an input type="text" it will reference that
    > inputelement.
    > If you use it in an image....
    >
    > Solution: simple give your form a name, and pass that to the function.
    > From your function you can use:
    > function update(formname) {
    > var formref=document.forms[formname];
    > var mon=formref.mon.value;
    > alert(mon);
    > }
    >
    > >
    > > need to do it like this as the form is created dynamically....

    >
    >
    > That is no reason to leave the names of the forms out. :)
    >
    > Good luck!
    >
    > Regards,
    > Erwin Moller
     
    Shippy, Jul 19, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tom
    Replies:
    4
    Views:
    9,918
    S. Justin Gengo
    Nov 13, 2003
  2. =?Utf-8?B?YzY3NjIyOA==?=

    how to pass value from first form to second form?

    =?Utf-8?B?YzY3NjIyOA==?=, Jan 11, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    892
    =?Utf-8?B?YzY3NjIyOA==?=
    Jan 11, 2006
  3. Iceman
    Replies:
    1
    Views:
    453
    Steve Pugh
    Jan 7, 2004
  4. Replies:
    1
    Views:
    407
  5. Phi!
    Replies:
    1
    Views:
    206
Loading...

Share This Page