Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old July 19th, 2006, 12:15 PM
Shippy
Guest
 
Posts: n/a
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....

  #2  
Old July 19th, 2006, 12:25 PM
Erwin Moller
Guest
 
Posts: n/a

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


Shippy wrote:
Quote:
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);
}
Quote:
>
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

  #3  
Old July 19th, 2006, 12:25 PM
Erwin Moller
Guest
 
Posts: n/a

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


Erwin Moller wrote:
Quote:
Shippy wrote:
>
Quote:
>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);
}
>
Quote:
>>
>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>


  #4  
Old July 19th, 2006, 12:35 PM
Shippy
Guest
 
Posts: n/a

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


Your an absolute STAR - many thanks!

completely forgot about "this." being related to that item...
Erwin Moller wrote:
Quote:
Shippy wrote:
>
Quote:
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);
}
>
Quote:

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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass information, classes between forms in Windows Applicationmode raylopez99 answers 12 July 25th, 2008 02:05 PM
URGENT: window.open does not render server-side code when aspx file pulled from a resource file Bob Jones answers 13 February 21st, 2007 03:35 PM
KeyDown not capturing all keys MLM450@hotmail.com answers 3 September 19th, 2006 12:05 PM
Using a form (with a combo box) to enter report criteria pelcovits@physics.brown.edu answers 3 November 13th, 2005 06:55 AM