0

Hi, I don't understand why it didn't release the output whereas I took this coding from my lecture

However, when I change 'selectedIndex' to 'value,' it simply provides the output. Your assistance is greatly appreciated by a newbie like me. :) <html> <head> <title>Menu Validation</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> function validate() { let price = document.forms["taxForm"]["price"].selectedIndex; if (price === 0) { alert ("Please select your Price."); return false; } let state = document.forms["taxForm"]["state"].selectedIndex; if (state === 0) { alert ("Please select your State."); return false; } return true; } </script> </head> <form name="taxform" method="GET" action=""> <select name="price"> <option>Choose Price</option> <option value="15000">15000</option> <option value="20000">20000</option> <option value="25000">25000</option> <option value="30000">30000</option> <option value="45000">45000</option> </select> <br><br> <select name="state"> <option>Choose State</option> <option value="0.029">Terengganu 2.9%</option> <option value="0.0625">Pahang 6.25%</option> <option value="0.04">Selangor 4%</option> <option value="0.07">Terengganu 7%</option> </select> <br><br> <input type="submit" value="Submit Form" onClick="return validate()"> </form> </html>

14th Nov 2023, 5:55 PM
Aenul
Aenul - avatar
7 Answers
+ 2
if you used .value instead of .selectedIndex, the value you would get is undefined instead of 0. then you should change the conditions to if(price==undefined) and if(state==undefined)
14th Nov 2023, 10:29 PM
Bob_Li
Bob_Li - avatar
+ 1
Ooo okay thank youu
14th Nov 2023, 10:48 PM
Aenul
Aenul - avatar
+ 1
Aenul you have typo. taxform not taxForm. Also, if you want to change undefined to a string value, you also have to add that value to the option. you are using the value attribute and your default choices don't have one, that is why .value is compared to undefined if you don't have a value assigned to an option. also price===undefined is not the same as price==='undefined' the first compares to undefined, the second compares to a string 'undefined' https://code.sololearn.com/Wbnoui5pOckL/?ref=app
15th Nov 2023, 3:53 AM
Bob_Li
Bob_Li - avatar
+ 1
I see.. okey Thankssss
15th Nov 2023, 4:33 AM
Aenul
Aenul - avatar
0
eh, I changed to 'undefined' but it doesn't give the alert output
15th Nov 2023, 3:37 AM
Aenul
Aenul - avatar
0
So i tried this <script> function validate() { let price = document.forms["taxForm"]["price"].value; if (price === "Choose Price") { alert("Please select your Price."); return false; } let state = document.forms["taxForm"]["state"].value; if (state === "Choose State") { alert("Please select your State."); return false; } return true; } </script>
15th Nov 2023, 3:40 AM
Aenul
Aenul - avatar
0
Hello everyone. Please what is wrong with this code below # Asks the user to enter the savings savings = input() # Convert the user input into a float value and update the variable savings = 150.0 # Savings grow after 1 year at a 5% annual interest rate balance = savings * 1.05 balance = 157.5 # Convert the balance into a string and update the variable balance = str(157.5) # Concatenate the 2 strings to produce a message message = ("Amount in 1 year " + "balance"); # Display the message print(type(message)); It's really stressing me and lots of time wasting
15th Nov 2023, 3:54 PM
Pascaline okolie
Pascaline okolie - avatar