Solved

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

Posted on 2008-10-14
12
707 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
give it like this...

<td class="data"> <a href="#" onclick="javascript:var Inv = <HSM name=Invnbr>;goback('Inv');"> <HSM name="Invnbr"></a> </td>
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:sijishJohn
Comment Utility
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
Comment Utility
Sorry mate, Still I get the same error.
0
 
LVL 4

Accepted Solution

by:
sijishJohn earned 500 total points
Comment Utility
try this..

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

Author Comment

by:narayanhy
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

763 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

14 Experts available now in Live!

Get 1:1 Help Now