Skip to content Skip to sidebar Skip to footer

Combing Js And Php On One Button. Is It Possible?

Hiya: i know some people would be so tired of my questions, but I'm working on a uni project and need to get it done as soon as possible. This question is about using JS on a butto

Solution 1:

This can be a way

Submit the form through JS after removing parameter

<scripttype="text/javascript">functionformAction(){
        var x=document.getElementById("collect")
        x.remove(x.selectedIndex);
        document.forms[0].submit();
    }

    </script>

Input type button

<inputtype="button" onclick="formAction()" name="Collect"  value="Collect" />

Solution 2:

Embed jQuery and use $.post() to send an AJAX request.

Solution 3:

JavaScript can interact with the button whilst the user is navigating the page and entering data into the form. The instant the user pushes the submit button and the request for the form submission is sent JS no longer has control. The request is sent to the form's action (most likely a PHP file) which processes the request and gives an answer back. If you really need to combine the two, look into AJAX.

Solution 4:

<?php print_r($_POST); ?><scripttype="text/javascript">functionformAction(){
    var x=document.getElementById("collect");
    x.remove(x.selectedIndex);
    submit_form();
}
functionsubmit_form() {
    document.form1.submit();
}
</script><formmethod="post"name='form1'><inputtype='hidden'name='Collect'/><selectid="collect"name="Select1"style="width: 193px"><option>guns</option><option>knife</option></select><inputtype="button"onclick="formAction()"name="Collect"value="Collect" /></form><?if (isset($_POST['Collect'])) {
    //do whatever update you want
    }

?>

Solution 5:

Simple Solution

Make this modification in the form tag

<formmethod="post"onsubmit="return formAction()">

In JavaScript function add a line "return true;" at the end of the function.

Voila ..!!! you are done..!!

Enjoy..!!

Post a Comment for "Combing Js And Php On One Button. Is It Possible?"