1

instead of using getParameterByName('Field', PostData) (PostData == $('form').serialize();)

I would like to write PostData.Field, how can i do that with javascript?

2
  • Is there a good reason not to use a selector such as $('input[name=Field]').val()? Commented Apr 17, 2010 at 23:46
  • ATM that is getting me the value of the first radio box and not what is currently selected. Commented Apr 18, 2010 at 1:59

2 Answers 2

2

You could write your own extension to return an object like you want, here's what that looks like:

jQuery.fn.MakeIntoFields = function() {
  var arr = this.serializeArray();
  var props = {};
  $.each(arr, function(i, f) {
    props[f.name] = f.value;
  });
  return props;
};

You'd call it by doing this:

var PostData = $("form").MakeIntoFields();

Then you could access the values with dot notation like you want:

PostData.fieldNameHere
//or...
PostData["fieldNameHere"]

You can see this working against a demo <form> here

Sign up to request clarification or add additional context in comments.

Comments

0

Do you mean something like this?

PostData = {
  field: $('input[name=Field]').val(),
  otherData: 'customdata'
};

1 Comment

No i mean obj = MakeIntoFields(PostData); obj.FieldName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.