Forum Moderators: open

Message Too Old, No Replies

href vs onclick

         

bagheera

7:09 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



I try yo use an image instead of a button to call a javascript function - but keep getting the error:
'this.form.outputDate is null or not an object'

the code is:

<a href="#" onclick="DoCal(this.form.outputDate);">
<img src="cal.gif" border="0" width="16" height="16"></a></td>

and the js:
<SCRIPT>

function DoCal(elTarget) {
if (window.showModalDialog) {
var sRtn;
sRtn = showModalDialog("calendar.htm","","center=yes;dialogWidth=350pt;dialogHeight=200pt");
if (sRtn!="")
elTarget.value = sRtn;
} else
alert("Internet Explorer 4.0 or later is required.")
}
</SCRIPT>

the onclick worked when it was a button....and Im bad at js...

thanks,

Rambo Tribble

7:36 pm on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the "this" keyword applies to the currently active object, your use of it must occur within the form in question.

bagheera

7:47 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



I have only one form and everything is within that so I dont quite understand what I need to do...

ajkimoto

8:03 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



It seems to me that anchor tags are not part of the form, so this.form will not work.

Try:

<a href="javascript:void(0)" onclick="DoCal(document.getElementById('outputDate'))"><img src="cal.gif" border="0" width="16" height="16"></a>

ajkimoto

bagheera

6:48 am on Apr 1, 2004 (gmt 0)

10+ Year Member



That worked ajkimoto thanks a lot!