Jump to content

how to add switch javascript


iamcat

Recommended Posts

hi,

 

i'm new with programming and i am supposed to create a simple calculator. i already have generated a script but i don't know how will i add case switch on it. you may refer to my code below:

<html>

    <head>

          <title> Sample Calculator </title>

    </head>

    <body>

           

<form method="post" action="calculator.asp">

          <table border="0">

          <tr>

                <td>Value 1: </td>

                <td><input type="text" name="value1"</td>     

          </tr>

          <tr>

                <td>Value 2: </td>

                <td><input type="text" name="value2"</td>

 

            </tr>

            <tr>

                <td>Operation: </td>

                <td><select>

                              <option value="add">+</option>

                              <option value="subtract">-</option>     

                              <option value ="divide">/</option>

                              <option value="multiply">*</option>

                </select>

                </td>   

            </tr>

            <tr>

            <td><input type ="submit" value="Submit" name="Submit Answer"></td>

   

            </tr>

              <tr>

                <td>Answer: </td>

                <td><input type="text"  name="answer">

                </td>   

            </tr>

 

        </form>

 

     

 

    </body>

</html>

 

can someone help me on how to add case switch or if-else statement in my code?

 

thanks in advance!  ::)

Link to comment
https://forums.phpfreaks.com/topic/234653-how-to-add-switch-javascript/
Share on other sites

Is that a school assignment or something? To create a calculator, first you need to catch events and get input and select values. After that you'll need to make the logic. Take a look at jQuery, a Javascript framework that will help a lot in selectors and dom manipulation (and much more actually).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.