Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > HELP. this.form does not seem to pass value...

Reply
Thread Tools

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

 
 
Shippy
Guest
Posts: n/a
 
      07-19-2006
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....

 
Reply With Quote
 
 
 
 
Erwin Moller
Guest
Posts: n/a
 
      07-19-2006
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

 
Reply With Quote
 
 
 
 
Erwin Moller
Guest
Posts: n/a
 
      07-19-2006
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>


 
Reply With Quote
 
Shippy
Guest
Posts: n/a
 
      07-19-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<location> element does not seem to work - Does anybody know how to solve this. alexvodovoz@yahoo.com ASP .Net 1 05-25-2007 01:12 AM
FileSystemWatcher does not seem to be working Nathan Sokalski ASP .Net 6 04-22-2006 01:37 AM
disabling html validation does not seem to stck Nalaka ASP .Net 12 01-18-2006 02:00 AM
Cookie does not seem to timeout Martin Dew ASP .Net 2 06-13-2005 02:40 PM
Webservice works once and then DOES NOT seem to work even though program does not crash Phi! ASP .Net Web Services 1 04-23-2004 08:42 AM



Advertisments