0

Forgive the complete newbie question here - I know this is really basic stuff, but for the life of me I can't figure it out. Javascript is relatively new to me, and this is the first time I've had to do this particular thing.

So, I'm trying to use a Modal to open an iframe - the page itself will have links to several modals, all of which need to be passed a different value. Rather than hardcode each of these, I'm trying to set it up in such a way that one function can be used and the links can pass the values as required.

The code I currently have successfully opens the modal, but a 404 error is inside it - plus the modal title shows + title + - so I guess I'm referencing it wrong (probably in the function?).

Heres what I've got, pointers in the right direction would be appreciated!

function openIframe(title,url){
    $.modal({
        title: '+title+',
        url: '+url+',
        useIframe: true,
        width: 600,
        height: 400
    });
}

.. and the link:

<a href="#" onclick="openIframe('Process Voucher','a_processvoucher.cfm')">Add</a>

2 Answers 2

2

To use the variables, don't quote them; title was being literally set to the string +title+ (and the same for url).

function openIframe(title, url) {
    $.modal({
        title: title,
        url: url,
        useIframe: true,
        width: 600,
        height: 400
    });
}​

It seemed you were getting confused over the concatenation syntax to join strings and variables; for example, see the following:

var name = "Matt";
var welcome = "Hi " + name +  ", how are you doing today?";
alert(welcome);

... will alert the string Hi Matt, how are you doing today?

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

1 Comment

Thank you! That sorted it :-)
1

You want to reference the variables called title and url, not strings with the values "title" and "url"

function openIframe(title,url) {
    $.modal({
        title: title, // no quotes
        url: url, // no quotes
        useIframe: true,
        width: 600,
        height: 400
    });
}

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.