Francesco
Francesco

Reputation: 95

pressing submit button with javascript

actually I have:

<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form" name="shipping-zip-form">
    <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php echo $this->__('Zip/Postal Code') ?></label>
    <div class="input-box">
        <input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo "04000"; ?>" />
    </div>
    <div class="buttons-set">
        <button type="button" id="send" title="<?php echo $this->__('Get a Quote') ?>" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
    </div>
</form> 

and I unsuccessful tried:

<script type="text/javascript">
    document.getElementById('send').submit();
document.forms['shipping-zip-form'].submit();

</script>

What I want to do it's quite simple, let javascript automatically press the button so submit the form. I will not need the submit button anymore, I need to automate the press button process. Thx

Upvotes: 1

Views: 1100

Answers (3)

papyrut
papyrut

Reputation: 71

You can use jQuery and try this :

   $(document).ready(function(){
   $('#send').click(function(){
           $('#shipping-zip-form').submit(); 
   });
});

Upvotes: 0

jon_brockman
jon_brockman

Reputation: 373

I"m guessing that your function isn't firing. Set it to execute on page load if that's when you'd like it to happen. Also, only <form> elements can be submitted so trying to target your <button id="send"> won't work.

window.onload {
    document.getElementById('shipping-zip-form').submit();
}

Upvotes: 1

Barmar
Barmar

Reputation: 782693

document.getElementById('shipping-zip-form').submit();

Upvotes: 1

Related Questions