Atom Ant Atom Ant - 6 months ago 21
Javascript Question

Select a table cell element and submit it in a form

I have a table that is dynamically generated with jQuery, it has 3

td
cells, with 10 values (returned by the server) in each cell. I want to select one of those values and submit it as part of a form. How should I do this?

Answer

Put each value inside those td's in a span and give the td's a class. You could put each value in a different hidden field, on click.

$("td.col1 span").click(function ()){
$("#var1").val(this);
}

<input type="hidden" name="var1" id="var1"/>

And then subit the form when 3 are selected.

//jquery

if(var1 != "" && var2 != "" && var3 != ""){
   $("#formId').submit();
}