I have a dynamic listing of products pulling from a MySQL Database. On the listing there is a Contact Now button which I am using a jquery Modal script for which pops up with a form.

My problem is trying to pass the product information variables to that popup.

I was thinking of adding the Brand and Model name using the rel attribue like this:

<a href="#" class="contact_now" rel="<?=$sku_brandname;?> <?=$sku_modelname;?>">Contact Now!</a>

and then with Javascript I can do this:

    $(".contact_now").click(function(){

    var rel = $(this).attr('rel');
    alert(rel);

which works perfect but on my Popup Div I'm not sure how to get that javascript rel variable to output it.

<p>Fill out the form below to inquire about the <strong>{ rel value here }</strong>.  We will get back to you as soon as possible.</p>

I'm not sure how to do this. If anyone has any ideas or suggestions I would appreciate it.

Thanks!

share|improve this question

which modal plugin do you use? – Manuel van Rijn Oct 13 '11 at 13:50
I use this: yensdesign.com/2008/09/… – Drew Oct 13 '11 at 13:53
so you want something like $("#popupContact strong").text(rel) – Manuel van Rijn Oct 13 '11 at 13:57
feedback

1 Answer

up vote 1 down vote accepted

Few things. First of all, if you want to store data in some nodes, you're better off using data attributes, like this:

<a href="#" class="contact_now" data-brand-name="<?=$sku_brandname;?>" data=-model-name="<?=$sku_modelname;?>">Contact</a>

You can then use jQuery to get them like this:

$(this).data("brandName");

As for the sending the variable to PHP thing, you should instead modify the value with JavaScript when you open the popup. (If it's not on the same page, say that in the comment.). To do that, you can give a span a class and modify it before showing the popup.

<p>Fill out the form below to inquire about the <span class="product"></span> We'll get back to you ASAP.</p>

Then in jQuery:

$(".product").text($(this).data("brandName"));
//Show popup
share|improve this answer
Awesome, just what I needed. Thank you SO much! – Drew Oct 13 '11 at 14:01
You're very welcome. – Xeon06 Oct 13 '11 at 14:03
Could the downvoter give some feedback? – Xeon06 Oct 13 '11 at 14:04
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.