1

I have a bit of Jquery written to add an image with an on click event but I am struggling to get the on click to alert the function that I have created the ultimate aim here is to build a window.open event that uses the lookURL variable as its a address.

To save placing loads of code in the question i have created a JS Fiddle below.

http://jsfiddle.net/justinerswell/qJFUa/5/

2
  • Your jsfiddle example alerts me with "This Works" when I click the image. What are you having trouble with? Commented Sep 12, 2011 at 10:16
  • I need to parse in the lookURL variable to build a window.open event Commented Sep 12, 2011 at 10:18

2 Answers 2

1

I'm not entirely confident I know what you're trying to do but if all you want to do is get the lookURL variable into the function that is executed when the click() is run, it's pretty easy: http://jsfiddle.net/XcAHx/

I've taken the onClick out of the HTML and into it's own function, and in there you can just reference the lookURL variable:

$("a").bind("click", function(e) {
     e.preventDefault();
     alert(lookURL);
});

Is that what you were after?

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

3 Comments

Awesome! thanks for that I wonder if you can help with the next bit! I have this field with the id of adds_postcode which is blank on page load i.e no value I then need to capture the user input eg.w10 1fb and use it in the lookURL function any thoughts?
DUDE you rock!!! I take it its just a case of replacing the alert with window.open?
Yep, pretty much. The variable fullURL stores the URL with postcode, so do with that what you please :)
1

You've done most of the work, just change

alert('This works')

to

myfunc('" + lookURL + "')

modified jsfiddle example

1 Comment

Hi thanks that works great, have hit another snag now I need to capture the input value after it has been typed by a user any thoughts on how?

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.