How to have different alerts for checkbox answers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to have different alerts for checkbox answers?

I have this checkbox code in html but i was wondering if you could do a if else statement in java depending on the answer? Also wondering if you can go to different websites depending on the answer? Here is the code in html: <form action="https://www.sololearn.com" method="POST" target="_blank"> <input type="checkbox" name="I enjoyed this"/>Male<br /> <input type="checkbox" name="I hated this"/>Female<br /> <input type="Submit" name="Submit"/>

23rd Apr 2020, 12:41 AM
Travis
Travis - avatar
2 Answers
+ 1
Yes you can do an if else statement and yes you can have a men's wearhouse website and a women's dress shop website linked. Both options are feasible.
23rd Apr 2020, 12:57 AM
BroFar
BroFar - avatar
0
I have found a way to do this. What i am wondering is in my statement that I want an alert based on an answer instead of going to a website if that is possible. here is my statement. I am sure it is in the form action but im not sure how to make that work : <form action="../" onsubmit="return checkCheckBoxes(this);"> <p><input type="CHECKBOX" name="CHECKBOX_1" value="This..."> This...</p> <p><input type="CHECKBOX" name="CHECKBOX_2" value="That..."> That...</p> <p><input type="CHECKBOX" name="CHECKBOX_3" value="...and The Other"> ...and The Other</p> <p><input type="SUBMIT" value="Submit!"></p> </form> <script type="text/javascript" language="JavaScript"> <!-- function checkCheckBoxes(theForm) { if ( theForm.CHECKBOX_1.checked == false && theForm.CHECKBOX_2.checked == false && theForm.CHECKBOX_3.checked == false) { alert ('You didn\'t choose any of the checkboxes!'); return false; } else { return true; } } //--> </script>
23rd Apr 2020, 1:59 AM
Travis
Travis - avatar