1

I have an input field and I want that variable to be passed as part of the url paramter in a load request. So for example what I am trying is

var inputField= $j('#inputText').val();
$j(document).ready(function() {     
    $j(".button").click(function (){    
        $j('#result').load('http://site.com?parameter='+inputField'.aClass')
    });
});

If I were trying to do this without the variable like

$j('#result').load('http://site.com?parameter=stuff .aClass')

it works fine

Can someone please show me the correct syntax to make this work?

2 Answers 2

2

You are missing a + in your code.

Try this(changed the code to include the $j('#inputText') in the ready event..just in case..

$j(document).ready(function() {     
   var inputField= $j('#inputText').val();
    $j(".button").click(function (){    
        $j('#result').load('http://site.com?parameter='+inputField +' .aClass')
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks... now it submits the request without error but it is no longer recognizing the specific element I am trying to grab ".aClass" but is instead appending that to the ?parameter=stuff.aClass
You mean you want to grab the element with the className .aClass and append its value to the URL?
it's missing a space after the, it's fixed in my answer, but yeah, it's a simple fix.
Thx..Followed the original post hence the space was missing. Updated the post.
0
$j(document).ready(function() {     
    $j(".button").click(function (){
        var inputField= $j('#inputText').val();    
        $j('#result').load('http://site.com?parameter='+inputField+' .aClass')
    });
});

4 Comments

Where I create the variable does not sem to be making any difference. Firebug is saying I am missing a ) after arguments list ?
yeah i missed it, it was missing a + after inputField.
@zac, and you didn't think posting the error message in your question might've been helpful?
@david.. yea sorry didnt notice that when i originally asked

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.