SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple calculation script

    Hi. I'm hoping someone can point out my mistake, because I can't seem to figure it out. (I'm sure it is something simple.) I trying to put together a very simple form that takes the selling price of a property and displays the commission amounts based on the plan. I got it to work no problem using PHP, but I wanted to use javascript so I didn't have to reload the page.

    The code I came up with is below, but I can't seem to get it to work. It appears that the onclick is not calling the function, but I don't see why not.

    Thanks for any help.
    Code JavaScript:
    <script type="javascript">
    function agentchoice(form)
    {
    var price = (document.myform.inputbox.value);
    var sanddollar = (price * .8) - 30;
    document.myform.sanddollar.value = sanddollar;
    var seashell = (price * .9) - 30 - 150;
    document.myform.seashell.value = seashell;
    var starfish = price - 150;
    document.myform.starfish.value = starfish;
    alert('starfish');
    }
    </script>
    <form name="myform" action="">
     
    <table>
    	<tr>
    		<td colspan="3">
    		<img src="images/agentchoice_logo.jpg" alt="Agent Choice Commision Calculator" />
    		</td>
    	</tr>
    	<tr>
    		<td>
    		<img src="images/Final_SandDollar2.jpg" alt="Sand Dollar Plan" />
    		</td>
    		<td>
    		<img src="images/Final_SeaShell2.jpg" alt="Seashell Plan" />
    		</td>
    		<td>
    		<img src="images/Final_StarFish2.jpg" alt="Star Fish Plan" />
    		</td>
    	</tr>
    	<tr>
    		<td class="commission">
    		Commission: <input type="text" name="sanddollar" />
    		</td>
    		<td class="commission">
    		Commission: <input type="text" name="seashell" />
    		</td>
    		<td class="commission">
    		Commission: <input type="text" name="starfish" />
    		</td>
    	</tr>
    	<tr>
    		<td colspan="3" style="padding:5px; text-align:right;">
    		Sale Price: <input type="text" name="inputbox">
    		<input type="button" name="button" value="Calculate" onclick="agentchoice(this.form)" />
    		</td>
    	</tr>
    </table>
    </form>

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by changing

    Code:
     
    <script type="javascript">
    to

    Code:
     
    <script type="text/javascript">
    I got the 'starfish' alert to pop up.

    I assume the code logic is correct since you said it works in php.

  3. #3
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was it. I knew it would be something simple I overlooked. Thanks!


Bookmarks

Posting Permissions

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