user3368504 user3368504 - 2 years ago 106
Javascript Question

Passing returned jquery var to another jquery

What is the best way to get the following returned var (in jQuery):

jQuery(document).ready(function() {
var theFormID = jQuery(parent.document).find('.theformclass').find('input[name="form_id"]').val();

the above code is ok as it returnes the value i need - so the question is how do i "paste" (print) it in the script that comes after it (where it says:

jQuery(parent.document).find('#abc_HERE-IS-WHERE-I-NEED-THE-RETURNED-VALUE_number_103').fadeToggle("slow", "linear");

thanks for your help :)

EDIT: thanks to @brian and @showdev - both solutions were correct, problem on my side was jquery sizzle.

works perfectly :) thank you again guys

Answer Source

EDIT: I cleaned up my answer a little bit, should be a bit more readable. You just need to break up your string and concatenate it with the returned value.

jQuery(document).ready(function() {
    var $parent = jQuery(parent.document); // cache this so jquery doesnt have to instantiate the same object twice

    var theFormID = $parent

    var $form = $parent
        .find("#abc_" + theFormId + "_number_103")
        .fadeToggle("slow", "linear");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download