0

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

2
  • 1
    You don't need the parens around the URL Commented Apr 27, 2012 at 12:56
  • 2
    And JavaScript use + for concatenation, not . Commented Apr 27, 2012 at 13:01

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

?=id should be ?id=... instead
1

Assuming a_href is a defined variable

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

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

Comments

1

Combining both answers:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.