Better way to change a value and display results?
I have a form that displays a number of results based on the value of a select list "#maxrows" (25, 50, 125, 250 results). "#startID" is a hidden input thats value is set to 1 that starts the displayed data from the first one. So each time you click "#next/#prev" it adds or subtracts from its value. Through PHP i display two buttons #previous and #next when the info is returned on the page via AJAX. Is there a better way to step through the results than this?
$(document).ready(function() {
$("#processing开发者_运维知识库").hide();
var options = {
target: '#return',
beforeSend: function() {
$('#processing').show()
},
complete: function() {
$('#processing').hide()
}
};
$('#SymbolSearchForm').ajaxForm(options);
});
function changestart(direction)
{
var rowsElement = $("#maxrows");
var rowsValue = parseInt(rowsElement.val());
var startElement = $("#startID");
var value = parseInt(startElement.val());
startElement.val(direction == "forward" ? value + rowsValue : direction == "back" ?
value - rowsValue : 1);
}
"#processing" is just the loading gif, im more concerned with the "function changestart(direction)" part
I don't think there is anything wrong with it if it works; don't overcomplicate things that work :). Just be sure you comment your code so you (and anyone else who reads your code) will know what is happening if they look at it.
Edit
The reason it isn't working is because you are using the ternary operator incorrectly.
startElement.val(direction == "forward" ? value + rowsValue : direction == "back" ? value - rowsValue : 1);
is invalid. It should be:
startElement.val(direction == "forward" ? value + rowsValue : value - rowsValue);
精彩评论