0

I couldn't seem to find any examples in the documentation of passing a jquery variable with a load statement. I tried with and without quotes, putting the whole variable statement in, but no luck. Everything else seems to work when debugging, but not passing a variable, please take a look: Edit: I should also make it clear I tried {term: d} and {term: var d} but neither work.

<script>
function callMe() {
    for (var i = 1; i< 2; i++){
        var b = $('#song'+i).val();
        var c = $('#artist'+i).val();
        var d = b +" "+ c; 
        // alert(d);
        //$('#results').load('getWeb.php', {term: d});
        $('#results').load('getWeb.php', {term: 'd'});
    }
    // var b = $('#song1').val();
    // alert(b);
}
$(document).ready(function(){
    callMe();
});
</script>

<form>
Song <input type ="text" name ="song1" id ="song1">
Artist <input type ="text"  name ="artist1" id ="artist1"><br />
<input type ='submit' value ='Submit' onClick="callMe();">
</form>
1
  • remove quotes from 'd' in {term:'d'}so it is a variable and not a string as you have it in the commented out line. How are you trying to receive this in php? Commented Mar 15, 2013 at 0:18

1 Answer 1

1

I made an working example for you. A starting point.

<?php
if (isset($_POST['term'])) {
    echo $_POST['term'];
    exit;
}
?><!DOCTYPE html>
<html>
    <head>
        <title>Info</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script type="text/javascript">
            function callMe() {
                var b = $('#song1').val();
                var c = $('#artist1').val();
                var d = b + ":" + c;
                $('#results').load('', {term: d});
            }
            $(function() {
                $('form').submit(function() {
                    callMe();
                    return false;
                });
            });
        </script>
    </head>
    <body>

        <form action="" method="post">
            Song <input type ="text" name ="song1" id ="song1">
            Artist <input type ="text"  name ="artist1" id ="artist1"><br />
            <input type ='submit' name="info" value ='Submit'>
        </form>
        <div id="results">

        </div>

    </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, this was amazingly helpful. Thanks so much for this, I was able to go off this and pretty much finish my project. Again thank you!

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.