HaLo2FrEeEk Posted July 28, 2007 Share Posted July 28, 2007 Is there any way to pass post variables to a Javascript without explicitly setting them as a parameter in the function name? For example, in AJAX, if I wanted to pass different url's with different parameters (like, page1 would have user_id, and count passed to it; page2 would have just a url passed to it) without making the javascript function look like this: function dosomething(url, param1, param2, param3) { // blah... } Could I just make the Javascript get whatever is in the form, no matter what or how many things are in it? Does this make sense? Quote Link to comment Share on other sites More sharing options...
ss32 Posted July 28, 2007 Share Posted July 28, 2007 you could pass an array... you would just have to have PHP format the POST array into something javascript can understand Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted July 28, 2007 Author Share Posted July 28, 2007 How would I go about doing that? Also, I saw a script that passed the form name as a getElementById variable, like: javascript:somefunction(document.getElementById(this.form)); I don't know how exactly that worked, but. Any more help would be really nice. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted July 29, 2007 Author Share Posted July 29, 2007 bump. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 you can also directly echo in variables into the raw js on page loads Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted July 30, 2007 Author Share Posted July 30, 2007 It's AJAX though, so I can't do that, I need to have different parameters passed to the javascript, the closest I've gotten is this: function ajax(url, div_id, param1, param2, elementname, element) { var poststr = param1+((param2 == null || param2 == '') ? "" : "&"+param2)+((element == null || element == '') ? "" : "&"+elementname+"="+document.getElementById(element).value); //alert(poststr); obj = document.getElementById(div_id); loading(); makePOSTRequest(url, poststr); } But that has it's flaws. Quote Link to comment 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.