3

Is it possible to redirect the end-user on checking/unchecking checkboxes ? How, please ?

I've tried to redirect him using get method with this code

HTML

<form><input type="checkbox" name="fixee" value="true" style="margin-left:40px;margin-right:3px;" /><input type="checkbox" name="nonFixee" value="true" style="margin-left:10px;margin-right:3px;" /></form>

jQuery

$("input[type='checkbox']").change(function () {
    if ($("input[name='fixee']").prop('checked') && $("input[name='nonFixee']").prop('checked')) {
        alert('2');
    }
    else if ($("input[name='fixee']").prop('checked') && $("input[name='nonFixee']").prop('checked')) {
        alert('3');
    }
    else{
        alert('1');
    }
});

http://jsfiddle.net/eKa8S/9/

I'm coding this in Visual Studio the ~ means the root folder of the project.

Any brilliant idea, please ?

Lucie kulza
  • 1,357
  • 6
  • 20
  • 31
  • Have you tried window.location.href? – markpsmith Feb 07 '14 at 12:48
  • Here is a stack overflow post which might help. http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript – Jeremy Quinton Feb 07 '14 at 12:49
  • 1
    @markpsmith, can you show me please how this works ? – Lucie kulza Feb 07 '14 at 12:50
  • Check these links .It may help you. [How can I make a redirect page in jQuery/JavaScript?][1] [How to manage a redirect request after a jQuery Ajax call][2] [1]: http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript [2]: http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call?rq=1 – Gaurav Dhavale Feb 07 '14 at 13:02

3 Answers3

0

You could use window.location = "~/Alertes/Index?fixee=true&nonFixee=true"

Marian
  • 1,154
  • 2
  • 15
  • 25
0

Your example rworked to do the get:

$("input[type='checkbox']").change(function () {
    if ($("input[name='fixee']").attr("checked") && !$("input[name='nonFixee']").attr("checked")) {
        window.location = "~/Alertes/Index?fixee=true&nonFixee=false";
    }
    else if (!$("input[name='fixee']").attr("checked") && $("input[name='nonFixee']").attr("checked")) {
        window.location = "~/Alertes/Index?fixee=false&nonFixee=true";
    }
    else {
        window.location = "~/Alertes/Index?fixee=true&nonFixee=true";
    }
});

Fiddle

Fabricio
  • 839
  • 9
  • 17
0

Try this,

$("input[type='checkbox']").change(function () {
    if ($("input[name='fixee']").prop('checked') && $("input[name='nonFixee']").prop('checked')) {
        window.location.href = '@Url.Action("Action1", "Controller")'
    }
    else if ($("input[name='fixee']").prop('checked') && $("input[name='nonFixee']").prop('checked')) {
         window.location.href = '@Url.Action("Action2", "Controller")'
    }
    else{
        window.location.href = '@Url.Action("Action3", "Controller")'
    }
});
Jaimin
  • 7,964
  • 2
  • 25
  • 32