Keith Power
Keith Power

Reputation: 14141

javascript url undefined redirect

I have some javascript to direct the page to a new url but I get directed to a www.myurl.com/undefined instead.

This is what I have, not sure what is wrong. I have tried also window.location

if (r == true) {
    window.location.href = ('http://www.myurl.com/pubs_delete.php?=id'.a_href)
};

Thank you for any pointers

Upvotes: 0

Views: 3371

Answers (4)

srini
srini

Reputation: 884

try something like this

      var a_href;
        if (r == true) {
            window.location.href = ('http://www.myurl.com/pubs_delete.php?=id'+a_href)
        };

javascript concatenation using +(plus) sympol ,you are using .(dot) sympol that is the problem for u

Upvotes: 1

Fran Verona
Fran Verona

Reputation: 5476

Combining both answers:

if (r) {   // r == true is quite redundat
    window.location.href = "http://www.myurl.com/pubs_delete.php?id=" + a_href;
};

Upvotes: 1

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123367

Assuming a_href is a defined variable

...delete.php?id=' + a_href

string concatenation in javascript is +, not . and the equal is misplaced

Upvotes: 1

gabitzish
gabitzish

Reputation: 9691

if (r == true) {
    window.location.href = 'http://www.myurl.com/pubs_delete.php?id=' + a_href
};

Upvotes: 1

Related Questions