gpt4 book ai didi

javascript - 简单的表单验证

转载 作者:行者123 更新时间:2023-11-30 13:37:16 26 4
gpt4 key购买 nike

发布#1

如何验证这个简单的表单(检查空字段字符串)?

                <p>Please select your Gift Certificate amount below. Please also enter your name and the Gift Certificate recipient's name. Once you click 'Buy Now' you will be sent to our Paypal site to complete the purchase.</p>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="sdsafsdafsadfdsafsdafsadfsadfsadfasdfsadfsdaf">
<table width="100%">
<tr>
<td width="130"><input type="hidden" name="on0" value="Amount"><p>Amount</p></td>
<td><select name="os0">
<option value="Option 1">$20.00</option>
<option value="Option 2">$50.00</option>
<option value="Option 3">$100.00</option>
</select></td>
</tr>
<tr>
<td><input type="hidden" name="on1" value="To:"><p>To (Full Name):</p></td>
<td><input type="text" name="os1" maxlength="60" size="30"></td>
</tr>
<tr>
<td><input type="hidden" name="on2" value="From:"><p>From (Full Name):</p></td>
<td><input type="text" name="os2" maxlength="60" size="30"></td>
</tr>
</table>

<table width="100%" style="margin-top: 10px;">
<tr>
<td><input type="hidden" name="currency_code" value="CAD">
<p><input type="image" src="BUTTON.jpg" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"></p>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></td>
<td align="right"><img src="../paypal_logo.jpg" alt="PayPal" /></td>
</tr>
</table>
</form>

发布#2

函数 validate_form(){ 有效=真;

    if ( document.GiftForm.os1.value == "" )
{
alert ( "Please fill in the 'Your Name' box." );
valid = false;
}
return valid;
}

-=-=-=-= 表格

        <form action="https://www.paypal.com/cgi-bin/webscr" method="post" method="GiftForm" onsubmit="validate_form( )">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="sdsafsdafsadfdsafsdafsadfsadfsadfasdfsadfsdaf">
<table width="100%">
<tr>
<td width="130"><input type="hidden" name="on0" value="Amount"><p>Amount</p></td>
<td><select name="os0">
<option value="Option 1">$20.00</option>
<option value="Option 2">$50.00</option>
<option value="Option 3">$100.00</option>
</select></td>
</tr>
<tr>
<td><input type="hidden" name="on1" value="To:"><p>To (Full Name):</p></td>
<td><input type="text" name="os1" maxlength="60" size="30"></td>
</tr>
<tr>
<td><input type="hidden" name="on2" value="From:"><p>From (Full Name):</p></td>
<td><input type="text" name="os2" maxlength="60" size="30"></td>
</tr>
</table>

<table width="100%" style="margin-top: 10px;">
<tr>
<td><input type="hidden" name="currency_code" value="CAD">
<p><input type="image" src="BUTTON.jpg" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"></p>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></td>
<td align="right"><img src="../paypal_logo.jpg" alt="PayPal" /></td>
</tr>
</table>
</form>

最佳答案

jQuery 是一个选项吗?有一个非常好的验证工具 http://docs.jquery.com/Plugins/Validation

关于javascript - 简单的表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4319318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com