Solved

Calling JavaScript Function using href inside a <td ...>

Posted on 2008-10-14
12
708 Views
Last Modified: 2010-04-21
Currently, on one screen , the following code to display the clicked invoice works.


           <td class="data"><a href="fin_InvoicePartList.htm?Invnum=<HSM name=Invnbr>&xxDealerCd=<HSM name=xxDealerCd>"><HSM name="Invnbr"></a></td>
 <td class="data"><HSM name=DlrOrd></td>
  <td class="data"><hsm name=SysOrd></td>
   <td class="data"><hsm name=OrdDate></td>

Now, I am working on a different screen which is a window. On that screen, when an invoice is clicked, I want to close the window and go back to the parent fields

To do this, I wrote a javascript function goback as below.
  function goback(in1) {
      var parent1 = opener.document;
    var parentField = parent1.getElementById("Invnum");
         parentField.value = in1;
       parentField.focus();
       window.close();
       }
 
Can I invoke this javascript function inside the href inside a <td>   ?

I tried the following two ways but without much success.  The code is not even going to the javascript function.

  <td class="data" <a href="javascript:goback(<HSM name=Invnbr>)"> <HSM name="Invnbr"></a> </td>

  <!--    <td class="data" onclick="goback(<HSM name=Invnbr>)"> <HSM name="Invnbr">  </td> -- > 

Please ignore the HSM tag. It is a local middleware thing and I can assure you that it does not interfere wih standard HTML/JavaScript.

Thanks a Lot.


0
Comment
Question by:narayanhy
  • 6
  • 5
12 Comments
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22717957
try this..

<td class="data" <a href="#" onclick="javascript:goback(<HSM name=Invnbr>)"> <HSM name="Invnbr"></a> </td>
0
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22717966
forget to close the td tag..

hope this will do..

<td class="data"> <a href="#" onclick="javascript:goback(<HSM name=Invnbr>)"> <HSM name="Invnbr"></a> </td>
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22717988
simply use onClick="this.window.close();"

that will return you to the parent, won't it?  Where else can it go?
0
 

Author Comment

by:narayanhy
ID: 22718022
I need to paswed the clciked invoice number to parent.

WHen I tried
<td class="data"> <a href="#" onclick="javascript:goback(<HSM name=Invnbr>)"> <HSM name="Invnbr"></a> </td>
Now, I get the display of invoices  now properly. But when I click on an onvoce numebr say 1234, I get errorsaying that
"1234" is undefined. I then trined goback(inv1=<HSM name=Invnbr>). Even this did not work.
Thanks a lot for your quick responses.

0
 

Author Comment

by:narayanhy
ID: 22718028
I get the error

"1234" is undefined on the line number where we have the statement having teh href as below.

<td class="data"> <a href="#" onclick="javascript:goback(<HSM name=Invnbr>)"> <HSM name="Invnbr"></a> </td>
Cheers
0
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22718044
give it like this...

<td class="data"> <a href="#" onclick="javascript:var Inv = <HSM name=Invnbr>;goback('Inv');"> <HSM name="Invnbr"></a> </td>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:sijishJohn
ID: 22718055
Oops...No need for quotes inside the method...

<td class="data"> <a href="#" onclick="javascript:var Inv = <HSM name=Invnbr>;goback(Inv);"> <HSM name="Invnbr"></a> </td>
0
 

Author Comment

by:narayanhy
ID: 22718096
Sorry mate, Still I get the same error.
0
 
LVL 4

Accepted Solution

by:
sijishJohn earned 500 total points
ID: 22718545
try this..

var Inv = <HSM name=Invnbr>.toString()
0
 

Author Comment

by:narayanhy
ID: 22727375
The solution originally proposed by sijishJohn is working now.

The following is the working bit.

 <a href="#"onclick="javascript:goback('<HSM name=Invnbr>');"> <HSM name=Invnbr></a> </td>

Thanks a Lot John !  

0
 

Author Closing Comment

by:narayanhy
ID: 31506185
Thanks a Lot John for your help. When i removed the variable definition and straight away put the  code, it worked.

Can u suggest a good educational site for HTML/javascript ?  
0
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22728003
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now