1

I have this code:

    var changedate  = document.getElementById("date");

    changedate.onchange = submitform;

    function submitform() {
    document.forms["form"].submit();

    }

However I have 3 submit buttons in my form, I want to call the submit button with ID 'save' with this function. How, can I do this, because at the moment when I change the value in 'date' the form gets submitted, but not in the way i manually push the submit button 'save' at the bottom of the form.

3 Answers 3

1

You can use :

document.getElementById("myForm").submit();

where myForm is id of your form.

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

2 Comments

Tried that, but strangely nothing happens right then.
Please try document.getElementById("date").addEventListener("change", function(){ document.getElementById("myForm").submit(); }); Please make sure that there is not duplicate ID. with form id.
0

Try adding <input type="hidden" name="submitbutton"> . In each button, before submitting set the value of this hidden field accordingly. In the code executed when date is changed, set the hidden value as how you set for the save button Eg:

<form method="post" action="something.php">
    <input type="submit" value="save" onsubmit="setType('save');return true;"/>
    <input type="submit" value="btn2" onsubmit="setType('btn2');return true;"/>
    <input type="submit" value="btn3" onsubmit="setType('btn3');return true;"/>
    <input type="hidden" id="hdn" value=""/>
</form>

In your js,

function setType(msg){document.getElementById('hdn').value=msg;}

and when date is changed,

setType('save');
document.forms["form"].submit();

Make sure you catch correctly in your php/asp file.

Comments

0

I think the problem comes after submitting the form:

There is a part:

<?php
if (isset($_POST['save'])) {

// do something 
}
?>

This is not executed because I dont click on the submit button 'save' in the form.

Comments

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.