简体   繁体   中英

Javascript form submit button not working innerHTML

I am using google maps api. When user moves marker on map submit button will change from disabled. It changes the button from disabled, but I can't submit the form. Nothing happens.

<div class="col-12">
    <form action="submit.php" method="POST" accept-charset="utf-8">
        <input type="text" name="name">
        <div id="submit-btn"><button class="generate-btn" type="submit" disabled>Select Location</button></div>
    </form>
</div>

Here is the listener from google maps.

google.maps.event.addListener(marker2, 'dragend', function (evt) {
    document.getElementById('submit-btn').innerHTML = '<button class="generate-btn" type="submit">Generate</button>';
});

I think instead of changing the inner HTML, you can simply do:

google.maps.event.addListener(marker2, 'dragend', function (evt) {
    document.getElementsByClassName('generate-btn')[0].disabled = false;
});

Instead of:

document.getElementById('submit-btn').innerHTML = '<button class="generate-btn" type="submit">Generate</button>';

Try with setting an ID to your button, like "submit_button", then remove the "disabled" property like this:

document.getElementById('submit_button').disabled = false;

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