1 Replies - 2001 Views - Last Post: 15 November 2009 - 08:25 AM

#1 kadiya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-November 09

Looking for help...script not working correctly

Posted 14 November 2009 - 10:43 PM

This is for an auction type form. The user would enter their ID then the amount they are bidding, clicking on the submit button to input it into a history window that also stamps the time it was entered. The current bid moves to the top of the list, with the highest bid shown in the high bid window.

The issue that I'm having, is that when I click the submit button, the only thing that shows in the history window is only one line with the time stamp only. The time stamp is over written if I input additional bids. The bidID and bidAmount does not show and the bidAmount is not showing in the highBid field.

Thanks in advance for any assistance with this, I'm feeling quite lost.

<title>Auction Log</title>
<link href="styles.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

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 = bidAmount[i];
	document.bidForm.bidId.value = " ";
	document.bidForm.bidAmount.value = " ";
	}
}

function addBid() {
	bidders.unshift("");
	bids.unshift("");
	
	var now = new Date ();
	var hours = now.getHours();
	var	minutes = now.getMinutes();
	var	seconds = now.getSeconds();
	
	minutes = minutes < 10 ? "0"+minutes : minutes;
	seconds = seconds < 10 ? "0"+seconds : seconds;
	
	var timeText = hours + ":" + minutes + ":" + seconds;
	
	bidTime.unshift(timeText);
	
	writeBid();
}

function removeBid() {
	bids.shift(bids(0));
	bidders.shift(bidders(0));
	bidTime.shift(bidTime(0));
	
	writeBid();
}


</script>

</head>

<body>
<form name="bidForm" id="bidForm">

<div id="head">
  <p>
	 <a href="#">Home</a> <a href="#">Auctions</a>
	 <a href="#">Features</a> <a href="#">Schedule</a>
	 <a href="#">Contacts</a>
  </p>
  <img src="logo.jpg" alt="Schmitt Auction Haus" /></div>

<div id="intro">
   <h1>Silent Auction</h1>
   <h2>Tawney Farm</h2>
   <table id="summarytable" border="2">
	  <tr>
		 <th>Lot #121</th>
		 <td>TurfTuff Lawn Tractor X24 (2003)</td>
	  </tr>
	  <tr>
		 <th>Current High Bid</th>
		 <td>
			<input id="highBid" name="highBid" readonly="readonly" />
		 </td>
	  </tr>
	  <tr>
		 <th>Bidding Ends</th>
		 <td>15:00</td>
	  </tr>
   </table>

   <table id="newbidtable" border="2">
	  <tr>
		 <th colspan="2" id="newtitle">Enter New Bid</th>
	  </tr>
	  <tr>
		 <th>Bidder ID</th>
		 <td>
			<input id="bidId" name="bidId" />
		 </td>
	  </tr>
	  <tr>
		 <th>Bid Amount</th>
		 <td>
			<input id="bidAmount" name="bidAmount" />
		 </td>
	  </tr>
	  <tr>
		 <th id="buttons" colspan="2">
			<input type="button" value="Submit" onclick="addBid()" />
			<input type="button" value="Remove Last Bid" onclick="removeBid" />
		 </th>
	  </tr>
   </table>

</div>

<div id="bidHistory">
   <h1>Bid History</h1>
   <p>
	  <textarea id="bidList" name="bidList"></textarea>
   </p>
</div>

<address>
   Schmitt AuctionHaus 
   3401 Rural Route 4 
   Fenbrook, IN  38012
</address>


</form>
</body>
</html>


This post has been edited by kadiya: 15 November 2009 - 03:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Looking for help...script not working correctly

#2 kadiya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-November 09

Re: Looking for help...script not working correctly

Posted 15 November 2009 - 08:25 AM

I've finally gotten the coding to input the time, bid and bid id into the text field, but I'm still having difficulties having each new bid move previous bids down a line with the highest bid only showing up in the high bid field. New code is:

<title>Auction Log</title>
<link href="styles.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

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();
	
	minutes = minutes < 10 ? "0"+minutes : minutes;
	seconds = seconds < 10 ? "0"+seconds : seconds;
	
	var timeText = hours + ":" + minutes + ":" + seconds;
	
	bidTime.unshift(timeText);
	
	writeBid();
}

function removeBid() {
	bids.shift(bids(0));
	bidders.shift(bidders(0));
	bidTime.shift(bidTime(0));
	
	writeBid();
}


</script>

</head>

<body>

<form name="bidForm" id="bidForm">

<div id="head">
  <p>
	 <a href="#">Home</a> <a href="#">Auctions</a>
	 <a href="#">Features</a> <a href="#">Schedule</a>
	 <a href="#">Contacts</a>
  </p>
  <img src="logo.jpg" alt="Schmitt Auction Haus" /></div>

<div id="intro">
   <h1>Silent Auction</h1>
   <h2>Tawney Farm</h2>
   <table id="summarytable" border="2">
	  <tr>
		 <th>Lot #121</th>
		 <td>TurfTuff Lawn Tractor X24 (2003)</td>
	  </tr>
	  <tr>
		 <th>Current High Bid</th>
		 <td>
			<input id="highBid" name="highBid" readonly="readonly" />
		 </td>
	  </tr>
	  <tr>
		 <th>Bidding Ends</th>
		 <td>15:00</td>
	  </tr>
   </table>

   <table id="newbidtable" border="2">
	  <tr>
		 <th colspan="2" id="newtitle">Enter New Bid</th>
	  </tr>
	  <tr>
		 <th>Bidder ID</th>
		 <td>
			<input id="bidId" name="bidId" />
		 </td>
	  </tr>
	  <tr>
		 <th>Bid Amount</th>
		 <td>
			<input id="bidAmount" name="bidAmount" />
		 </td>
	  </tr>
	  <tr>
		 <th id="buttons" colspan="2">
			<input type="button" value="Submit" onclick="addBid()" />
			<input type="button" value="Remove Last Bid" onclick="removeBid" />
		 </th>
	  </tr>
   </table>

</div>

<div id="bidHistory">
   <h1>Bid History</h1>
   <p>
	  <textarea id="bidList" name="bidList"></textarea>
   </p>
</div>

<address>
   Schmitt AuctionHaus 
   3401 Rural Route 4 
   Fenbrook, IN  38012
</address>


</form>
</body>
</html>



Here is what the book is asking us to do:

2) insert an embedded script with three new arrays named bids, bidders, and bidTime. Do not populate these arrays with values.

3) Insert a function named writeBid(). This is to write the bidding history and highest current id to the web page. There are no parameters for this function. Add the following commands to the function:
a. declare a variable named historyText, setting it's initial value to an empty text string. This is used to record bidding history.
b. insert a For loop in which the counter variable goes from 0 through the length of the bids array in increments of 1. Each time through the loop, append the following text string to the historyText variable: bidTime bids (bidders) \n where bidTime, bids, and bidders are the current items in the bidTime, bids, and bidders array based on the value of the counter variable. Note that \n is an escape character indicating a new line, and causes the next entry to the historyText variable to be placed on a new line (not working for me)
c. After the For loop finishes, write the value of the historyText variable to the text area box with the name bidList. (bidForm is the form and bidList is the field)
d. write the value of the first item in the bids array to the highBid field.
e. set the values of the bidId and bidAmount fields to empty text strings.

4) Create a function named addBid(). Purpose is to add a bid to the start of teh bids, bidders, and bidTim arrays. Add following commands:
a. Using the unshift() array, insert the current value of the bidID field to the start of the bidders array.
b. Using the unshift() array, insert the current value of the bidAmount field a the start of the bids array.
c. Declare a variable named now containing a date object for the current date and time.
d. Extract the hours, minutes, and seconds values from the now variable, storing these values in variables named hours, minutes, and seconds.
e. Use a conditional operator to insert leading zeroes in the minutes and seconds values if they are less than 10.
f. Create a variable named timeText equal to the text hours:minutes:seconds where hours, minutes, and seconds are the value of the hours, minutes, seconds variables.
g. Using the unshift() array method, insert the value of the timeText variable at the start of the bidTime array.
h. call the writeBid() function.

5) Create a function named removeBid(). Purpose is to remove the first entry from the bids, bidders, and bidTime arrays. Add the following commands:
a. Using the shift() array method, remove the first entry from the bids array.
b. repeat the previous step to remove the first entry from the bidders and bidTime arrays.
c. call the writeBid() function

6. scroll down the document to the submit input button. Add an event handler attribute to run the addBid() function when the button is clicked.

7. add an event handler attribute to the Remove Last Bid button to run the removeBid() function when the button is clicked.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1