Wednesday, September 14, 2011

Setting the input className to the object value

The code below creates and set the value of the object when filling out a form. This can be used for POST or GET method request.

<input type="text" class="balls" />
<input type="text" class="bat" />
<script>
var stat = {
data: {date: '2011-02-01', type: 'balls'},
column: //sets the value to stat.data
function(){
$('input').focusout(function () {
var attr = $(this).attr("class");//get the attribute (className) of tag
//create and set value for the object
stat.data[attr] = $(this).val(); //set value to stat.data
});
}() //this autostarts the function
}
<script/>

From locahost/stats website

No comments:

Post a Comment