Javascript显示窗体的隐藏变量
Javascript Show hide variable for form
这是我遇到的每个人都有问题的代码。这是我已经工作了8个小时,因为我不知道js。我大部分都是从w3school.com网站上得到的,我一直在努力把所有的东西拼凑在一起。呃,请帮助
<script type="text/javascript">
var stringToMatch = 'christopher',
input = document.getElementById('text'),
div = document.getElementById('divColor1');
function toggle (switchElement){
if (this.value == stringToMatch){
div.style.display = 'block';
}
else {
div.style.display = 'none';
}
};?
</script>
<!--This is the start of the code which i want to appear-->
<h3>Coupon Redeem</h3>
<form action="test" method="post">
Please type in the Coupon Code you have recieved:
<form id='coupon' onChange="javascript: ShowMenu(document.getElementById('text').value,'divColor1');">
<input id="text" type="text">
<input type="button" id="text" value="Redeem" onClick="toggle(this)" />
</form>
<!--This is the start of the hidden field that i want to appear when the coupon code is entered correctly-->
<div id="divColor1" style="display:none;">
<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="asjsanxci">
<input type="hidden" name="on0" value="Tokens">Tokens
<select name="os0">
<o ption value="5 tokens">5 tokens$5.00 USD</option>
<option value="10 tokens">10 tokens$10.00 USD</option>
<option value="15 tokens">15 tokens$13.00 USD</option>
<option value="20 tokens">20 tokens$18.00 USD</option>
<option value="25 tokens">25 tokens$23.00 USD</option>
<option value="30 tokens">30 tokens$27.00 USD</option>
<option value="35 tokens">35 tokens$33.00 USD</option>
<option value="40 tokens">40 tokens$38.00 USD</option>
<option value="50 tokens">50 tokens$45.00 USD</option>
</select>
<input type="hidden" name="on1" value="Username Verification">Username Verification
<input type="text" name="os1" maxlength="200">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
</form>
</div>
<br>
</form>
您的代码出现语法错误
<div id="divColor1" style="displayed:none"
将其更改为
<div id="divColor1" style="display:none;">
还有一些其他的错误,我发现
<form id='coupon' onChange="javascript: ShowMenu(document.getElementById('text').var,'divColor1',);">
ShowMenu缺少一个变量和另一个语法错误document.getElementById('text').var
>
<form id='coupon'
onChange="javascript: ShowMenu(document.getElementById('text').value,'divColor1');">
更新我对你的代码做了一些更改。你可以在这里看到工作代码
更新代码
<script>
var stringToMatch = 'christopher';
function toggle (){
var input = document.getElementById('text').value;
if (input == stringToMatch){
document.getElementById('divColor1').style.display = 'block';
}
else {
document.getElementById('divColor1').style.display = 'none';
}
};
</script>
<!--This is the start of the code which i want to appear-->
<h3>Coupon Redeem</h3>
<form action="test" method="post">
Please type in the Coupon Code you have recieved:
<form id='coupon' onChange="javascript: ShowMenu(document.getElementById('text').value,'divColor1');">
<input id="text" type="text">
<input type="button" id="text" value="Redeem" onClick="toggle()" />
</form>
<!--This is the start of the hidden field that i want to appear when the coupon code is entered correctly-->
<div id="divColor1" style="display:none;">
<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="asjsanxci">
<input type="hidden" name="on0" value="Tokens">Tokens
<select name="os0">
<o ption value="5 tokens">5 tokens$5.00 USD</option>
<option value="10 tokens">10 tokens$10.00 USD</option>
<option value="15 tokens">15 tokens$13.00 USD</option>
<option value="20 tokens">20 tokens$18.00 USD</option>
<option value="25 tokens">25 tokens$23.00 USD</option>
<option value="30 tokens">30 tokens$27.00 USD</option>
<option value="35 tokens">35 tokens$33.00 USD</option>
<option value="40 tokens">40 tokens$38.00 USD</option>
<option value="50 tokens">50 tokens$45.00 USD</option>
</select>
<input type="hidden" name="on1" value="Username Verification">Username Verification
<input type="text" name="os1" maxlength="200">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
</form>
</div>
<br>
</form>
修复代码
displayed:none => display:none
var input = document.getElementById('text');
// your html don't have id='text'
<input type="text"> => <input id='text' type="text">
你必须解决两个问题,然后
它有效!
祝你好运。
相关文章:
- 将值连接到隐藏变量
- 如何隐藏变量
- Javascript显示窗体的隐藏变量
- 如何在使用servlet处理时使用javascript设置隐藏变量的值
- 获取函数的表单隐藏变量
- 获取从函数到 php 的表单隐藏变量
- JavaScript中的隐藏变量,它是如何工作的
- 使用 AJAX 将隐藏变量解析为另一个 jsp 文件
- JSTL:foreach 循环将值设置为隐藏变量始终返回零
- 使用VB访问Javascript中隐藏变量的值
- 通过javascript设置隐藏变量在Wordpress 3.3.1管理插件页面中不起作用
- 元素.隐藏变量可移植性
- 如何从createRange对象中排除隐藏变量
- 试图在onclick中插入PHP变量,以便设置隐藏变量
- 无法在aspx页面中访问javascript中的代码隐藏变量
- 基于隐藏变量的值执行客户端验证
- 如何在jquery中设置隐藏变量的值
- 如何获得ajax返回id隐藏变量..在请求页面
- 在函数内的函数中赋值隐藏变量
- HTML表单隐藏变量不显示在php