-2

$(".btn").click(function(){
  $('<div></div>').appendTo('body')
        .html('<div> Select </div>')
        .dialog({
            modal: true, title: 'Select', zIndex: 10000,autoOpen:true,
            width: 'auto', 
            resizable: false,
            draggable: false,
      modal: true,
      hide: { effect: "clip", duration: 1000 },
            buttons: {
             A: function () {
              window.location.href="xyz.php?param=A";
                },
                B: function () {
                  window.location.href="xyz.php?param=B";
                }
            },
            close: function (event, ui) {
             
            }
        });
 });
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"> </script>
<div class="btn">Click</div>

I am trying to redirect when there is a button clicked. Current Implementation redirects to myHomePage/0 or myHomePage/1. None of my params are set and redirecting php also not working.

What is wrong in this? Please let me know.

Gibbs
  • 21,904
  • 13
  • 74
  • 138

2 Answers2

1

Plz try this code

$(".btn").click(function(){
   var redirectId = $(this).attr('redirectId');
   window.location.href = "http://ursite.com/"+redirectId;
 });

in html

<div redirectId="1" class="btn">Click</div>
Shibon
  • 1,552
  • 2
  • 9
  • 20
1

Could do something like this:

jQuery:

$("div.btn").click(function(){
    var href = $(this).attr("href");

    if(typeof href !== typeof undefined && href !== false){
        window.location.href = href;
    }
});

HTML:

<div href="newlocation.php" class="btn">Click</div>

It will work on all div's with a class of btn, that contain the href attribute!

GROVER.
  • 4,071
  • 2
  • 19
  • 66
  • I know it. I have to use dialog. User has to select A or B. Then I have to redirect it. – Gibbs Jan 27 '17 at 09:05