How to pass a value from JS to a HTML hidden input field
How to pass a value from JS to a HTML hidden input field
I want to take the value that assigned to the variable 'sData' and place it in a HTML hidden input field. The javascript below resides in the header section. I'm having problems getting the value to be properly placed in a hidden input field on my HTML page to be passed to my server for querying and processing.
// Individual cell data
$(document).ready(function() {
oTable = $('#example').dataTable();
oTable.$('tr').click( function () {
var sData = oTable.fnGetData( this )[0];
// alert( 'The cell clicked on had the value of '+sData );
} );
} );
... I want the sData value to be placed in an HTML input field in the body of the page similar to this:
input type="hidden" id="lookup" name="lookup" value="sData"
How would I achieve this, and where should any code additions be placed?
Thanks for your help!
// Individual cell data
$(document).ready(function() {
oTable = $('#example').dataTable();
oTable.$('tr').click( function () {
var sData = oTable.fnGetData( this )[0];
// alert( 'The cell clicked on had the value of '+sData );
} );
} );
... I want the sData value to be placed in an HTML input field in the body of the page similar to this:
input type="hidden" id="lookup" name="lookup" value="sData"
How would I achieve this, and where should any code additions be placed?
Thanks for your help!
This discussion has been closed.
Replies
$('#lookup').val(sData[n]); // n being the index when sData is an array
$('#lookup').val(sData); // sData not an array
[/code]