Jump to content

script flexibility


HaLo2FrEeEk

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.