Welcome Guest, Not a member yet? Register   Sign In
Retrieve value of hidden form field with jQuery
#6

[eluser]Nick Husher[/eluser]
Suggestion: create code conventions for deriving CSS paths for elements you need to access. The easiest way to do this is to give every form a descriptive and unique ID attribute and then "filter" by that in your jQuery selectors. You can have multiple forms on the same page with the same field name attributes, but you can only (well... should only; having more than one is considered an undefined use case) have one instance of an ID per page.

Code:
<form id="log-in-form">
  <input type="hidden" name="hidden-field" value="hidden-login-value" />
</form>
<form id="register-form">
  <input type="hidden" name="hidden-field" value="hidden-register-value" />
</form>

[jquery]
var getHiddenValue = function(form) {
   return $('#' + form + '-form input[name="hidden-field"]').eq(0).val();
};

var foo = getHiddenValue('register'); // = 'hidden-register-value';
var bar = getHiddenValue('log-in'); // = 'hidden-login-value';
[/jquery]

(Code is untested)


Messages In This Thread
Retrieve value of hidden form field with jQuery - by El Forum - 03-11-2010, 03:13 PM
Retrieve value of hidden form field with jQuery - by El Forum - 03-11-2010, 03:35 PM
Retrieve value of hidden form field with jQuery - by El Forum - 03-11-2010, 03:52 PM
Retrieve value of hidden form field with jQuery - by El Forum - 03-11-2010, 03:55 PM
Retrieve value of hidden form field with jQuery - by El Forum - 03-11-2010, 03:59 PM
Retrieve value of hidden form field with jQuery - by El Forum - 03-11-2010, 04:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB