limitphp Posted February 13, 2009 Share Posted February 13, 2009 Is it possible to change this part in a function used by multiple forms: function myfunc(num){ document.frmPlaylist.newName.value; } into this: function myfunc(num){ document.frmPlaylist+num.newName.value; } in other words, I have a page that may have a bunch of forms on it.... each form would be called frmPlaylist4, frmPlaylist35, frmPlaylist22, etc.... I want to send that number to the function and make it part of the form name. Is that possible? thanks Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/ Share on other sites More sharing options...
KevinM1 Posted February 13, 2009 Share Posted February 13, 2009 Is it possible to change this part in a function used by multiple forms: function myfunc(num){ document.frmPlaylist.newName.value; } into this: function myfunc(num){ document.frmPlaylist+num.newName.value; } in other words, I have a page that may have a bunch of forms on it.... each form would be called frmPlaylist4, frmPlaylist35, frmPlaylist22, etc.... I want to send that number to the function and make it part of the form name. Is that possible? thanks Use something along the lines of: function myFunc(num) { document.forms["frmPlaylist" + num].elements["newName"].value = "blah"; } Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761485 Share on other sites More sharing options...
limitphp Posted February 13, 2009 Author Share Posted February 13, 2009 Is it possible to change this part in a function used by multiple forms: function myfunc(num){ document.frmPlaylist.newName.value; } into this: function myfunc(num){ document.frmPlaylist+num.newName.value; } in other words, I have a page that may have a bunch of forms on it.... each form would be called frmPlaylist4, frmPlaylist35, frmPlaylist22, etc.... I want to send that number to the function and make it part of the form name. Is that possible? thanks Use something along the lines of: function myFunc(num) { document.forms["frmPlaylist" + num].elements["newName"].value = "blah"; } How would I do that with checkboxes, if I had multiple ones with the same name? right now i use: document.frmPlaylist.playlist[a].checked would I convert that into this: document.forms["frmPlaylist" + num].elements["playlist"][a].checked ? Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761496 Share on other sites More sharing options...
corbin Posted February 13, 2009 Share Posted February 13, 2009 Why not just pass "this" into the function? For example: <form onsubmit="SomeFunction(this);"> Then the parameter would be the same thing as what you would get with document.formname. Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761500 Share on other sites More sharing options...
limitphp Posted February 13, 2009 Author Share Posted February 13, 2009 Why not just pass "this" into the function? For example: <form onsubmit="SomeFunction(this);"> Then the parameter would be the same thing as what you would get with document.formname. thanks for the tip corbin, I thought about that...but I can't....because I call the function when they click the submit button, not the checkboxes and textbox..... its complicated.....its for an ajax request..... anyway, Nightslyr, it worked!!!!!! my goodness, you are awesome! Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761503 Share on other sites More sharing options...
corbin Posted February 13, 2009 Share Posted February 13, 2009 What does a submit button do? It submits a form >.<. If you do onsubmit="blah(); return false;" The form will not submit. Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761514 Share on other sites More sharing options...
limitphp Posted February 13, 2009 Author Share Posted February 13, 2009 What does a submit button do? It submits a form >.<. If you do onsubmit="blah(); return false;" The form will not submit. Actually thats not true....I tried that. I moved my ajax call to the <form tag instead of the button and when I tried to put the ajax function in front of the return false, it submitted the darn thing..... anyway, I really appreciate you responding corbin. You're always willing to help m out and I really appreciate that. Even when Maq and premiso get tired of my butt. ultimately, I like using this: document.forms["frmPlaylist" + num].elements["newName"].value = "blah"; because it gives you even more control.... Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761519 Share on other sites More sharing options...
corbin Posted February 13, 2009 Share Posted February 13, 2009 Example of non-submitting form: <script language="javascript"> function blah(f) { return false; } </script> <form action="blah.html" method="GET" onsubmit="return blah(this);"> <input type="hidden" name="hidden" value="omg a value!" /> <input type="submit" /> </form> But, what ever works ;p. Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761606 Share on other sites More sharing options...
limitphp Posted February 13, 2009 Author Share Posted February 13, 2009 Example of non-submitting form: <script language="javascript"> function blah(f) { return false; } </script> <form action="blah.html" method="GET" onsubmit="return blah(this);"> <input type="hidden" name="hidden" value="omg a value!" /> <input type="submit" /> </form> But, what ever works ;p. Oh yeah...I could have just put it all in one function..... yeah, I guess that would have worked too... Quote Link to comment https://forums.phpfreaks.com/topic/145095-solved-need-function-to-work-with-multiple-forms/#findComment-761622 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.