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
Related Q & A:
- How to create deep object with dynamic name in Javascript?Best solution by Stack Overflow
- How do I override an object method in JavaScript?Best solution by stackoverflow.com
- Object reference not set to an instance of an object; null?Best solution by Stack Overflow
- How to dynamically create object properties from an array in Javascript?Best solution by nfriedly.com
- What is hyperlink? How to hyperlink?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.