How to pass a javascript object back to the server?

Trouble in passing form object to javascript from hyperlink?

  • 1. <a href="javascript:SelectAll(this.form)">A… </a> 2.<input type ="button" value ="test" onClick="SelectAll(this.form);" /> <script ......> function SelectAll(form) { alert(form); } </script> method 1 produce an alert message 'undefined' while 2 method works fine by displaying form object . I'm very much aware that anchor elements don't have a `form` property, that references the form , unlike input elements,but is there any alternative way to pass form object using hyperlink or is there any way to style the button to look like an hyperlink Thanks

  • Answer:

    You could pass the id of the form w/ the link into a function to the get the object and pass that object to ur method.... something like this <script type="text/javascript"> function SelectAll(form) { alert(form); } function GetElement(id) { if (document.getElementById(id)) { return document.getElementById(id); } else { return false; } } </script> <a href="javascript:SelectAll( GetElement('form1') );" onclick="">blah</a>

ganeshgu... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.