how would i go about making a function on a checkbox that pops up one alert menu when its checked and pops a different alert when its unchecked? here's what i have so far i know its wrong i dont know how to change the beginning script: function compare(bing) { if ("bing"=checked) { alert("You agree, your favorite search engine is also bing."); } else { alert("you disagree, your favorite search engine is not bing."); } } Code (markup): later in the html i have this button named bing <input type="checkbox" checked name="bing" value="Click Me" onClick="message()"></input> Code (markup):
Try something like this <input type="checkbox" checked="checked" name="bing" value="Click Me" onClick="message()"></input> Code (markup): function message() { if (document.myform.bing.checked) { alert("checked"); } else { alert("unchecked"); } } Code (markup):
what about a button how would i go about adding a button that pops up the specific alert (determined by checked box from the compare function ) when clicked this is what i have so far <input type="button" value="Check Me" onClick="compare()" > Code (markup): i want that button to pop up the specific alert (if check box is checked, pop up the "yes" alert, if its not checked, pop up the "no" alert) when clicked
You can use the same code. document.myform.bing returns form element regardless of the event which triggers the function.