I'm new to Javascript and working on a problem, it's about making a website that allows a user to input a bid on an item along with a bid id. When they input both they press the submit button and the bid/bid id (along with the date and time) will display in a textarea.
It should allow for multiple bids to be submitted and to display but currently I can only get one to display. Any help as to how I can get multiple bids to display would be appreciated. Thank you
var bids = new Array();
var bidders = new Array();
var bidTime = new Array();
function writeBid() {
var historyText = " ";
for (var i = 0; i < bids.length; i++) {
historyText = bidTime[i] + " " + bids[i] + " " + bidders[i] + "\n";
document.bidForm.bidList.value = historyText;
document.bidForm.highBid.value = bids[i];
document.bidForm.bidId.value = " ";
document.bidForm.bidAmount.value = " ";
}
}
function addBid() {
bidders.unshift(document.bidForm.bidId.value);
bids.unshift(document.bidForm.bidAmount.value);
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeText = hours + ":" + minutes + ":" + seconds;
bidTime.unshift(timeText);
writeBid();
}
function removeBid() {
bids.shift();
bidders.shift();
bidTime.shift();
writeBid();
}
bidListis the textarea, then use...bidList.value += historyText- that is, use+=instead of=. (Or, better, use+=to add to yourhistoryTextvariable and only set the...bidList.valueonce after the loop.) Why are you displaying that sort of data in a textarea? Is it supposed to be editable?