Monday, December 30, 2013

[jQuery]: Get and Set value in html element

1. Get value from html input element

$(document).ready(function() {
var test= $('#test_id').val();//get value from input with id #test_id
        alert('test: ' + test);
});

2. Get value from html label element

$(document).ready(function() {
var test= $('#test_id').text();//get value from label with id #test_id
        alert('test: ' + test);
});

3. Set value into html hidden element

$(document).ready(function() {
var test= $('#test_id').text();//get value from id #test_id
        alert('test: ' + test);
        $('#hidden_field').val(test);//set value test into id #hidden_field
});

No comments: