www.webdeveloper.com
Results 1 to 4 of 4

Thread: Novice needs Javascript assistance

  1. #1
    Join Date
    May 2011
    Posts
    15

    Novice needs Javascript assistance

    Hi all,

    I have a calculator I've created with different text fields for users to input data. Then I have a calculate button to bring up a pop-up window (a lightbox) and display the result. Now that all works fine but I want the calculate button to check the text fields first to make sure data is there before the pop-up even opens. If there isn't anything there, I don't want the pop-up to open.

    The calculate button code is...

    <a href="#TB_inline?height=360&width=380&inlineId=popup" class="thickbox" onClick="checkValue(); calculateTotal(); true" >
    <input type="button" name="Button" value="OK" class="OK" /></a>

    Is there a way to stop the 'a href' from happening until there is data in the text fields??

    Any help would be greatly appreciated! Thanks!

    Ben

  2. #2
    Join Date
    May 2011
    Posts
    24
    could be the code itself put the entire calculator code up and we may see the problem

  3. #3
    Join Date
    May 2011
    Posts
    15
    <p>Your Current Rent Per Week?</p>
    <img src="_images/dollar.png" alt="$" width="30" height="30" class="noImgBorder" />
    <input type="text" name="rent" id="rent" value="" onKeyPress="return numbersonly(this, event)" />
    <p>Your Current Management Fee?</p>
    <img src="_images/percent.png" alt="%" width="30" height="30" class="noImgBorder" />
    <input type="text" name="fee" id="fee" value="" onKeyPress="return numbersonly(this, event)" />
    <p>Other Fees Per Annum?</p>
    <img src="_images/dollar.png" alt="$" width="30" height="30" class="noImgBorder" />
    <input name="otherFees" type="text" id="otherFees" value="" onkeypress="return numbersonly(this, event)" />
    <a href="#TB_inline?height=360&width=380&inlineId=popup" class="thickbox" onClick="checkValue(); calculateTotal(); true" >
    <input type="button" name="Button" value="OK" class="OK" /></a>
    <div id="popup">
    <p class="popuph1">Your Savings:</p>
    <span class="symbols2">$</span><input name="total" id="total" type="text" class="result" readonly="readonly" onkeyup="addCommas(this.value)"/>

  4. #4
    Join Date
    May 2011
    Posts
    15
    The Javascript...

    Code:
    function checkValue() {
    var defaultValue;
    
    defaultValue = 0;
    
    if ((document.getElementById("otherFees").value)=="")
    	(document.getElementById("otherFees").value)=defaultValue;
    }
    
    
    function calculateTotal() {
    var total;
    var rent;
    var fee;
    var other;
    
    rent = parseInt((document.getElementById("rent").value) * 52);
    fee = parseFloat(document.getElementById("fee").value) / 100;
    other = parseInt(document.getElementById("otherFees").value);
    
    total = ((rent * fee) + other) - 1249;
    
    document.getElementById("total").value = Math.floor(total);
    
    if (total<0) {
    	alert("Your savings are below Pure Rentals flat fee. Please contact us for a confidential chat about we can help.");
    }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles