简体   繁体   中英

jQuery : Element not defined error (but defined)

I have some form in my page,it forms does not hard code,
All forms have a name and unique ID.
But when calling that forms,console sat NOT DEFINED.
I want submit forms with jQuery,but forms not defined,
I tried with:

alert(jQuery("#paypal_form_-5").length);
//output is 0

and

document.getElementById('paypal_form_-5').submit();

and etc.. But does not work.......

form code

<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" name="paypal_form_-5" id="paypal_form_-5" method="POST">
            <input type="hidden" value="http://www.domain.com/2014/index.php?option=domain&amp;view=addon_payments&amp;type=return" name="return">
            <input type="hidden" value="2" name="rm">
            <input type="hidden" value="_xclick" name="cmd">
            <input type="hidden" value="rajnvr@rctech.org" name="business">
            <input type="hidden" value="USD" id="paypal_form_currency_code_-5" name="currency_code">
            <input type="hidden" value="http://www.domain.com/2014/index.php?option=domain&amp;view=addon_payments&amp;type=cancel" name="cancel_return">
            <input type="hidden" value="http://www.domain.com/2014/components/domain/views/addon_payments/paypal_ipn.php" name="notify_url">
            <input type="hidden" value="GOLD Membership" name="item_name">
            <input type="hidden" value="20" id="paypal_form_amount_-5" name="amount">
            <input type="hidden" value="http://www.domain.com/2014/components/domain/views/addon_payments/paypal_ipn.php" name="notify_url">
            <input type="hidden" value="001" name="item_number">
            <input type="hidden" value="2740" name="custom">
            <span id="paypal_price_title_-5" class="paypal_price_title">GOLD Membership&nbsp;20&nbsp;USD</span>
            <input type="button" onclick="send_request_to_paypal_express(-5);" value="Pay" name="button_-5">
</form>

Add the JS bellow your HTML or wrap your JS by

$(document).ready(function(){/*Your code*/});

Demo: http://jsfiddle.net/4c9p7/

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