-4

I need to add the calculated membership fee to my membership application page for my amateur radio club. From what I read I need to use ID. But I am still having issues getting it to work. Below is a portion of the page that has the javascript in it. Any help is greatly appreciated.

                    <tr>
                        <td width="5%">&nbsp;</td>
                        <td class="bosytext" width="15%">Membership Period</td>
                            <td class="bosytext" width="75%"><input type="number" name="membershipterm"  id="term" required="required"> $22 for single year membership/ $20 per multi-year membership</td>
                            <td width="5%">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="5%">&nbsp;</td>
                        <td width="15%">Fee</td>
                        <script>
                    var fee;
                    var term;

                    if term = 1 {
                        (fee = 22;
                    } else {
                        fee = 20;
                    }
                    //calculates membership fee
                    var totalFee = (fee * term)
                    // outputs calced membership fee to html
                            document.getElementById('totalFee')
                    </script>
                        <td width="75%">id="totalFee</td>
                        <td width="5%">&nbsp;</td>
                    </tr>
3
  • Can you please reformat the question and it would be more helpful if u add simulated code which can run. Commented Sep 18, 2019 at 19:30
  • 1
    Your code has syntax errors. Commented Sep 18, 2019 at 19:31
  • You have to supply more details but can look at stackoverflow.com/questions/19644906/… Commented Sep 18, 2019 at 19:31

2 Answers 2

0

Your code has lots of syntax errors.

Try this:

<html>

<body>

<table style="width:100%">

                    <tr>
                        <td class="bosytext" width="15%">Membership Period</td>
                            <td class="bosytext" width="75%">
                                <input type="number" name="membershipterm" id="term" required="required">
                                <button onclick="calc()">calc</button> 
                                $22 for single year membership/ $20 per multi-year membership </td>

                    </tr>

                    <tr>
                        <td width="15%">Fee</td>

                        <td width="75%" id="totalFee"></td>                       

                    </tr>
</table>



  <script>
    function calc(){
        var term = document.getElementById('term').value;
        var fee;

               if (term == 1) {
                        fee = 22;
                    } else {
                        fee = 20;
                    }


                    var totalFee = (fee * term);

                    document.getElementById('totalFee').innerHTML = totalFee

    }
  </script>                    

</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

In HTML id is used as a link to an HTML element. You set it in the tag you want to reference:

<td width="75%" id="totalFee></td>

You can then get that tag and manipulate it from js:

let total_Fee = (fee * term);
document.getElementById('totalFee').value = total_Fee;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.