I tried to google, but couldn't find anything abou开发者_开发技巧t this situation, mb I googled bad :) whatever, all i need is to create a form with one input checkbox, when the checkbox is checked it goes to a link, when it is not checked, it follow another link, for now im stuck right here:
<form name="eol" method="post"
action="/index.cfm?fuseaction=objects2.view_product_list&eol=1">
Show EOL Products<input type="checkbox" name="eol_input" value="0" <cfif not isdefined('attributes.eol')><cfelse>checked</cfif> onClick="eol.submit();">
</form>
how do i make it follow the other link when the checkbox is NOT checked?! i think it can be done by javascript(jquery), so does anyone have any idea?
Thanks for help!
$("[name='eol_input']").click(function(){
if(this.checked){
//is checked
window.location = "http://link1.com/";
} else {
//not checked
window.location = "http://link2.com/";
}
});
Is this the kind of thing you're after?
$(document).ready(function() {
$('form[name="eol"]').submit(function(event) {
event.preventDefault();
event.stopPropagation();
var urls = {
"checked" : "http://foo.com/",
"unchecked": "http://bar.com/"
};
var isChecked = $('input[name="eol_input"]:checked').length;
window.location = isChecked ? urls['checked'] : urls['unchecked'];
});
});
精彩评论