Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts

    SELECT input not being read correctly

    all,

    i have a function that deletes a DOM table and then recreates it based on the values that input by the user. i have a page that has two text's on it and 3 select combos on it. when i reload the page, enter the values for the first time, the table populates correctly. if i simply change the values and not reload the page, and then click my "calc" button again, the table populates correctly EXCEPT for the "payment period" select combo box value, if it is indeed has been changed. here is the portion of my code that populates the table rows:
    Code:
      var i = 1
      if (document.getElementById("paymentperiod").value == "Monthly") {
      	var Period = 12;
    	var PeriodStr = "m";
    	var PeriodAdd = 1; }
      else if(document.getElementById("paymentperiod").value == "Semi-Monthly") {
      	var Period = 24;
    	var PeriodStr = "d";
    	var PeriodAdd = 365/12/2; }
      else if(document.getElementById("paymentperiod").value == "Bi-Weekly") {
      	var Period = 26;
    	var PeriodStr = "d";
    	var PeriodAdd = 14; }
      else { var Period = 52;
     	var PeriodStr = "d";
    	var PeriodAdd = 7; }
      	var LoanDate = CDate(document.getElementById("loandate").value) //Loan Begin Date
      var field1 = LoanDate;
      var field2 = document.getElementById("loanamount").value; //Payoff Amount
      var field3 = document.getElementById("rate").value; //Interest Rate
      var field5 = parseInt(field2 * field3 / Period); //Interest Paid for the period
      var field4 = parseInt(document.getElementById("paymentamount").value - field5);
      var field6 = field2 - field4;
    
      // Insert rows and cells into bodies.
      while (field6 > 0)
      //for (i=0; i<6; i++)
      {
        var oBody = (i<2) ? oTBody0 : oTBody1;
        oRow = document.createElement("TR");
        oBody.appendChild(oRow);
    	  for (j=1; j<=6; j++)
        {
    	 	oCell = document.createElement("TD");
    		if (j == 1) 	{
    			oCell.innerHTML = field1;
    						}
    		else if (j == 2){
    			oCell.innerHTML = field2;
    						}
    		else if (j == 3){
    			oCell.innerHTML = field3;
    						}
    		else if (j == 4){
    			oCell.innerHTML = field4;
    						}
    		else if (j == 5){
    			oCell.innerHTML = field5;
    						}
    		else if (j == 6){
    			oCell.innerHTML = field6;
    						}
    			oRow.appendChild(oCell);
        }
    		field1 = AddDate(PeriodStr, PeriodAdd, field1);
    		field2 = field6
    		field5 = parseInt(field2 * field3 / Period);
    		field4 = parseInt(document.getElementById("paymentamount").value - field5);
    		field6 = field2 - field4;
    		i = i + 1
      }
    here is the input type that is causing me problems:
    Code:
    <select name="paymentperiod" size="1" id="paymentperiod" style="width:150px">
      <option value="52">Weekly</option>
      <option value="26">Bi-Weekly</option>
      <option value="24">Semi-Monthly</option>
      <option value="12">Monthly</option>
    </select>
    if i change all of the inputs on my page and then recalc the table, everything registers except the payment period value. does anyone see an error? i cannot seem to find it. thanks!

  • #2
    New Coder
    Join Date
    Mar 2007
    Posts
    98
    Thanks
    24
    Thanked 4 Times in 4 Posts
    Umm, I could be wrong about this, but in your IF statements you are calling the value of the select options as words "Monthly" etc, however in the select table you are setting the values as numbers. I cannot see where you are telling the function that the number value = the words.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,857
    Thanks
    78
    Thanked 4,417 Times in 4,382 Posts
    longman is right. The value= in an <option> *overrides* whatever text you put between the <option> and </option>.

    There are lots of other things I would change in that code. WHY would you use names such as field1, field2, etc., in place of READABLE names such as paymentDate, balanceDue, interestRate, periodicInterest, amountToPrincipal, newBalance ???

    Ehhh...and other things kind of odd, but that's a start.

  • #4
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    longman is right. The value= in an <option> *overrides* whatever text you put between the <option> and </option>.

    There are lots of other things I would change in that code. WHY would you use names such as field1, field2, etc., in place of READABLE names such as paymentDate, balanceDue, interestRate, periodicInterest, amountToPrincipal, newBalance ???

    Ehhh...and other things kind of odd, but that's a start.
    i do not program js Pedant, but thanks for the guidance. this page was thrown together with no care at all, but at least it works.

    and i also figured out that i was using the labels in the dropdown instead of the actual values. it works fine with the values being referenced instead. problem solved...

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by ajetrumpet View Post
    this page was thrown together with no care at all, but at least it works.
    Mate, seriously, if you're going to do something, have a bit of pride and do it correctly. That's the attitude which leads to all of the crap script and code which people have to wade through on a daily basis whether they like to or not.

    Do things right or pay someone else to do so for you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •