Hi. Not sure where to put this but basically I have a form. There are two buttons. One says submit and the other says print form.

How do I make sure that the user has clicked the print form button before the form gets submitted.

For example, a user fills out my form and then hits submit. If they didn't click submit first, a javascript error will pop up and say "print form". If they did print the form befor hitting submit, it will allow the form to pass on to the proper page.

Heres what I was thinking of using but not sure how to code it correctly.

$('#Submit, #Print').click(function () {
    if (this.id == 'Submit') {
        alert('Print the Form First!');
    }
    else if (this.id == 'Print') {
        //Continue Form action.
    }
});

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

there is a variety of ways to do this.
Declare a global variable which flags to true when the buttons is pressed. Then use an if statement saying if flag == true do next bit.

Yes as @imthwee said there are many ways to do it.

One way is to keep Submit button disable unless Print button is clicked.

Or Another way is to disable print button after click Print button,
and check on click of Submit button wether Print is disabled (i.e. Print is clicked) or not.
If it is disabled it means it has clicked. Else User is directly clicking print button
Sample code

<script>
function myFunction(var1)
{
    var buttonValue=var1.value
    if(buttonValue=='Submit')
    {
        //document.getElementsByName('print').value
        var printB=document.getElementById("print");
        if(!(printB.disabled))
        {
            alert("Please print first before submit");
        }
        else
        {
            alert("Submitted succesfully");
        }
    }
    else if(buttonValue=='Print')
    {
          alert("Print");
          document.getElementById("print").disabled = true; 
    }
}
</script>

<button type="button" name="submit" value="Submit" id="submit" onclick="myFunction(this)">Submit</button>
<button type="button" name="print"  value="Print" id="print" onclick="myFunction(this)" >Print</button>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.