0

HTML:

<select id="single">
    <option>Single</option>
    <option>Single2</option>
  </select>
<input value="load()" id="test" type="submit" />
<div id="result"></div>

Script:

$.ajaxSetup ({  
cache: false  
}); 
var loadUrl = "http://localhost/test/process.php";  
    $("#test").click(function(){  
          $("#result").load(loadUrl, "content=sd345f"+singleValues);  
    });
    function displayVals() {
      var singleValues = $("#single").val();
    }
    $("select").change(displayVals);
    displayVals();

That is my current code, I'm new to jquery and what i wanna ask is how do i make the var singleValues update when i choose a list from a dropdown and append it as a get value when i click on submit?

ANd here's process.php BTW:

<?php file_put_contents('1.txt',$_GET['content']); ?>

1 Answer 1

2

If I understand right, you want to load the result when you click on the button.

Try the following code:

$("#test").click(function(){
    // get the selected value
    var value = $("#single option:selected").val();

    // GET to server
    $.ajax({
        type : "GET",
        url : "http://localhost/test/process.php",
        data : {
            "content" : value
        }, 
        success : function(response){
            $("#result").html(response);
        }
    });
    // Don't use default submit function
    return false;
});

More information about $.ajax http://api.jquery.com/jQuery.ajax/

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

2 Comments

Only when i click on the submit button.
what if the dropdown and submit button was in a loop? pastebin.com/vTxGeEk4

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.