0

main.php:

<SCRIPT type="text/javascript">     

    $("#btnSubmit").click(function () {                 
        alert("What will i put here!");
    });

</SCRIPT>      

<input type = "submit" id = "btnSubmit" value = "Try IT!" />

<div id = "show_search2">
</div>

output.php:

<?php $val = $_POST['btnSubmit'];
echo "<H1>$val</H1>"; ?>

What specific jQuery functionality can get the value of the btnSubmit and access it through $_POST and output it to the div show_search2? I used prototype.js but it provides conflict with my other JS scripts in the index.

Note: all my script source is included in index and that's why I didn't include the source in this post.

1 Answer 1

1

Do you mean something like this:


$("#btnSubmit").click(function (e) {
    e.preventDefault();
    var submitVal = $(this).val();
    $.ajax({
       type: "POST",
       url: "url_of_your_output.php",
       data: {btnSubmit : submitVal},
       success: function(response) {
            $("#show_search2").html(response);  //response from output.php
       }
    });
});


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

4 Comments

yes something like that, can i actually $_POST the btnSubmit value or a textbox? can i change submitVal = $('txtUserName').val(); and submit it to the php script and dispplay the output as it is ?
yes of course, you could do submitVal = $('#txtUserName').val(); to get value of input field having id = txtUserName and pass it in
you could add a form wrapping the input and submit fields
i just did what you said but it didn't work. it is just redirected on my index page.

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.