Javascript显示表单的隐藏变量
这是我和每个人都有麻烦的代码。这是我8个小时以来一直在做的,因为我不知道js。我从w3school.com网站上获得了大部分信息,只是一直在尝试将所有信息整合在一起。啊,请帮忙Javascript显示表单的隐藏变量,javascript,Javascript,这是我和每个人都有麻烦的代码。这是我8个小时以来一直在做的,因为我不知道js。我从w3school.com网站上获得了大部分信息,只是一直在尝试将所有信息整合在一起。啊,请帮忙 <script type="text/javascript"> var stringToMatch = 'christopher', input = document.getElementById('text'), div = document.getElementById('divColor1');
<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>
var stringToMatch='christopher',
输入=document.getElementById('text'),
div=document.getElementById('divColor1');
功能切换(开关元件){
如果(this.value==stringToMatch){
div.style.display='block';
}
否则{
div.style.display='none';
}
};?
息票兑换
请输入您收到的优惠券代码:
代币
5枚代币$5.00美元
10枚代币$10.00美元
15枚代币$13.00美元
20枚代币$18.00美元
25枚代币$23.00美元
30枚代币$27.00美元
35代币33.00美元
40枚代币$38.00美元
50枚代币$45.00美元
用户名验证
修复代码
displayed:none => display:none
var input = document.getElementById('text');
// your html don't have id='text'
<input type="text"> => <input id='text' type="text">
显示:无=>显示:无
var input=document.getElementById('text');
//您的html没有id='text'
=>
那么你必须解决两个问题
它起作用了
祝你好运。你的代码有语法错误
<div id="divColor1" style="displayed:none"
更新
我对你的代码做了一些更改。您可以看到工作代码
更新代码
<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>
var stringToMatch='christopher';
函数切换(){
var输入=document.getElementById('text')。值;
如果(输入==stringToMatch){
document.getElementById('divColor1').style.display='block';
}
否则{
document.getElementById('divColor1').style.display='none';
}
};
息票兑换
请输入您收到的优惠券代码:
代币
5枚代币$5.00美元
10枚代币$10.00美元
15枚代币$13.00美元
20枚代币$18.00美元
25枚代币$23.00美元
30枚代币$27.00美元
35代币33.00美元
40枚代币$38.00美元
50枚代币$45.00美元
用户名验证
my bad,我正在从我的编辑器修复这里的代码,然后我写了显示。谢谢你指出。是的,它说显示根本不起作用。你的代码有两个问题,一个是显示,另一个是id文本字段OK,所以还不能正常工作。你认为我的提交按钮放错地方了吗?还有ShowMenu我该怎么处理它呢?我一直在搞乱代码,因为ShowMenu的javascript中没有变量,所以我把它去掉了。这是我到目前为止所拥有的。。。优惠券兑换请输入您收到的优惠券代码:@nextlevelgamingCO您是否已对blueiur和我提到的所有必要更改进行了更改..如果是,请更新您的code@nextlevelgamingCO你的代码仍然有很多错误。我做了一些更改。检查我的答案,看看它是否有效。。我还将JSFIDLE linkSibu放在这里,我看到它正在工作。但可悲的是,在咖啡杯编辑器中测试它,它似乎恨我或其他什么,哈哈。我把javascript放在头标签里了,对吗?那么剩下的是html吗?我也在使用IE。这可能是问题所在。
<form id='coupon' onChange="javascript: ShowMenu(document.getElementById('text').var,'divColor1',);">
<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>