ballhogjoni Posted November 14, 2008 Share Posted November 14, 2008 I want to send the form object to a function when a link is clicked. How would I do that? code: <form name="form1" action=""> <input>... <a href="JavaScript:splitDate(this);>test</a> </form> Quote Link to comment https://forums.phpfreaks.com/topic/132743-how-to-pass-the-form-to-a-javascript-function/ Share on other sites More sharing options...
F1Fan Posted November 14, 2008 Share Posted November 14, 2008 <form name="form1" action=""> <input>... <a href="JavaScript:splitDate(this.form);>test</a> </form> Quote Link to comment https://forums.phpfreaks.com/topic/132743-how-to-pass-the-form-to-a-javascript-function/#findComment-690317 Share on other sites More sharing options...
ballhogjoni Posted November 14, 2008 Author Share Posted November 14, 2008 is says that form undefined <form name="form1" action=""> <input>... <a href="JavaScript:splitDate(this.form);>test</a> </form> function splitDate(form) { var checkin_dates = form.checkin.value.split("/"); } Quote Link to comment https://forums.phpfreaks.com/topic/132743-how-to-pass-the-form-to-a-javascript-function/#findComment-690322 Share on other sites More sharing options...
KevinM1 Posted November 14, 2008 Share Posted November 14, 2008 Try: <script type="text/javascript"> window.onload = function() { var form1 = document.forms["form1"]; var splitLink = document.getElementById("splitLink"); splitLink.onclick = function() { splitDate(form1); } function splitDate(form) { var checkin_dates = form.checkin.value.split("/"); } } </script> . . . <form name="form 1" action=""> <input>... <a href="#" id="splitLink">test</a> </form> One thing I noticed, as well, is that you're not doing anything with your checkin_dates variable. You assign something to it, but that value is gone once the function is out of scope. You should declare that variable in the global space (where I declared my two variables) if you actually want to retain checkin_dates. Quote Link to comment https://forums.phpfreaks.com/topic/132743-how-to-pass-the-form-to-a-javascript-function/#findComment-690332 Share on other sites More sharing options...
F1Fan Posted November 14, 2008 Share Posted November 14, 2008 Maybe this: <form name="form1" action="" id="form1"> <input>... <a href="JavaScript:splitDate('form1');">test</a> </form> function splitDate(form) { var checkin_dates = document.getElementById(form).checkin.value.split("/"); } Quote Link to comment https://forums.phpfreaks.com/topic/132743-how-to-pass-the-form-to-a-javascript-function/#findComment-690344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.