[jQuery] help using selectors to set a hidden field value
Hi all,
Pretty basic but Im having some difficulty. When my form is submitted,
I want to capture all the form element textfield values where the name
begins with 'rlinehval-' and put them into a hidden field value with
the id "updstr" as a semicolon delimited list for a db update. I read
through the selector docs but this doesnt seem to work.
Using Jquery I am trying this:
$(document).ready(function(){
$('[@name^=rlinehval-]').each(function(){
var sv = this.value + ";";
$("#updstr").val(sv);
});
});
So in the case of the example form below, when submitted I collect all
the values for the fields where the name starts with ''rlinehval-" and
put them in a hidden field value as a semicolon delimited string
On submission the hidden field named "updstr" would be:
0056543,DVD;0024543,BLU
Simple demo form
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('[@name^=rlinehval-]').each(function(){
var sv = this.value + ";";
$("#updstr").val(sv);
});
});
</script>
</head>
<body>
<form id="myform" class="cssform" action="">
<input type="hidden" id="updstr" name="updstr" value="">
<label for="user">Item1</label>
<input name="rlinehval-1" type="text" id="rlinehval-1"
value="0056543,DVD" />
<label for="user">Item2</label>
<input name="rlinehval-2" type="text" id="rlinehval-2"
value="0024543,BLU" />
<input type="submit" value="Submit" />
<input type="reset" value="reset" />
</form>
</body>
</html>