Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: <!DOCTYPE html> <head> <title>Function for drop down list and radio</t

ID: 3548426 • Letter: Q

Question

Question:


<!DOCTYPE html>

<head>
    <title>Function for drop down list and radio</title>
</head>

<body>

    <script>
    
        function display()
        {
        
            var num1, num2, result, ope;
            
            num1=parseInt(document.frm.num1.value);
            num2=parseInt(document.frm.num2.value);
            
            for(var i=0; i<document.frm.length; i++)
            {
            
                if(document.frm.ope[i].selected)
                {
                
                    ope=document.frm.ope[i].value;
                
                }
            
            }
            
            if(ope=="Multiply")
            {
            
                result=num1*num2;
            
            }
            
            else if(ope=="Addition")
            {
            
                result=num1+num2;
            
            }
            
            else if(ope=="Subtraction")
            {
            
                result=num1-num2;
            
            }
            
            else
            {
            }
            
            document.write("Result is "+result);
            alert("Rsult"+result);
            
        }
    
    </script>

    <h2>LET's Learn Math</h2>
    
    <form name=frm>
    
        <br/>1st number:
        <input type="text" name="num1"  size="20"/>

        <br/>2st number:
        <input type="text" name="num2" size="20"/>

        
        <br/>Operation:
        <select name="ope">
            <option value="Multiply">Multiply
            <option value="Addition">Addition
            <option value="Subtraction">Subtraction
        </select>
        
        <br/><br/>
        
        <input type="submit" value="Calculate"/>
        <br/>
    
    </form>

</body>

</html>


Please correct my code and using comment explain what i wrong.

Explanation / Answer

The correct code is pasted below...


There was nothing wrong in ur code except few parentheses :)

Use either eclipse or any other IDE while writing ur code, u will never miss such things then :)


Code :


<!DOCTYPE html>


<head>

<title>Function for drop down list and radio</title>

</head>


<body>


<script>


function display()

{


var num1, num2, result, ope;


num1=parseInt(document.frm.num1.value);

num2=parseInt(document.frm.num2.value);


for(var i=0; i<document.frm.length; i++)

{


if(document.frm.ope[i].selected)

{


ope=document.frm.ope[i].value;


if(ope=="Multiply")

{


result=num1*num2;


}


else if(ope=="Addition")

{


result=num1+num2;


}


else if(ope=="Subtraction")

{


result=num1-num2;


}


else

{

}



document.write("Result is "+result);

alert("Rsult "+ result);


}


}


}


</script>


<h2>LET's Learn Math</h2>


<form name=frm>


<br/>1st number:

<input type="text" name="num1" size="20"/>


<br/>2st number:

<input type="text" name="num2" size="20"/>



<br/>Operation:

<select name="ope">

<option value="Multiply">Multiply

<option value="Addition">Addition

<option value="Subtraction">Subtraction

</select>


<br/><br/>


<input type="submit" value="Calculate"/>

<br/>


</form>


</body>


</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote