简体   繁体   中英

how to execute first php function than javascript function onclicking/submiting a submit button

i have this input field:

<input type="submit"  name="rregjistro" value="Rregjistro Tani Te Dhenat" onclick="openmodal()" >

I want first to execute POST script in PHP and than to open a modal popup using a javascript function.

Can you please help me! Thanks in advance!

It is not possible to click using PHP because form submission is the action on the client's side, ie in your browser. Events in the browser like this can be executed by javascript or other client language.

<form ... >
<input type="submit"  name="rregjistro" value="Rregjistro" />
<!-- remove onclick attribute for now -->

</form>

<div id="myResult"></div>

<script>
$(function(){
    $("input[name=rregjistro]").click(function(){
        // url needs to belong to your domain
        $.ajax({url: "/your_url_path", success: function(result){
            $("#myResult").html(result);
            open();
        }});
    });
});
</script>

You would still need to start with a javascript function first.

In jquery that would be something like that:

function open() {
  $.post('http://url', $('#form').serialize(), function() {
    alert('popup goes here');
  })
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM