admin管理员组文章数量:1419624
I have a problem i have the following javascript function:
<script type="text/javascript">
<!--
function BothFieldsIdenticalCaseSensitive() {
var two = document.bid_deal.passphrase_hidden.value;
var three = document.bid_deal.passphrase.value;
if(two == three) { return true; }
alert("Warning!! passcodes must match!!!");
return false;
}
//-->
</script>
I am using it to pare two text fields to make sure the two text fields match themselves. it is working for one set of text fileds but has refused to work if i add another set of text field and run another instance of the same function.
I have a call javascript function calling checkEnableSubmit when the action is executed but i dont know why it won't work with more than one set of text fields. I however noticed that both call javascript behaviors in the page call the same name of checkEnableSubmit. If i change the name one stops working.
HERE IS THE JAVASCRIPT CALL:
<input name="passphrase" type="text" id="passphrase" onfocus="clearDefault(this)" onblur="MM_callJS('checkEnableSubmit')" value="Nopass" />
I need to implement this script to add validation to my text fields, please i need help BADLY!!!!
I have a problem i have the following javascript function:
<script type="text/javascript">
<!--
function BothFieldsIdenticalCaseSensitive() {
var two = document.bid_deal.passphrase_hidden.value;
var three = document.bid_deal.passphrase.value;
if(two == three) { return true; }
alert("Warning!! passcodes must match!!!");
return false;
}
//-->
</script>
I am using it to pare two text fields to make sure the two text fields match themselves. it is working for one set of text fileds but has refused to work if i add another set of text field and run another instance of the same function.
I have a call javascript function calling checkEnableSubmit when the action is executed but i dont know why it won't work with more than one set of text fields. I however noticed that both call javascript behaviors in the page call the same name of checkEnableSubmit. If i change the name one stops working.
HERE IS THE JAVASCRIPT CALL:
<input name="passphrase" type="text" id="passphrase" onfocus="clearDefault(this)" onblur="MM_callJS('checkEnableSubmit')" value="Nopass" />
I need to implement this script to add validation to my text fields, please i need help BADLY!!!!
Share Improve this question edited Jun 27, 2013 at 17:29 Ronnie 11.2k22 gold badges84 silver badges142 bronze badges asked Jun 27, 2013 at 17:27 Ralph E. EmekaRalph E. Emeka 151 gold badge2 silver badges8 bronze badges 3- Could you add your html here ? – MAK Ripon Commented Jun 27, 2013 at 17:34
- Add your html and also the code for checkEnableSubmit – Matthew Graves Commented Jun 27, 2013 at 17:41
- Can you provide a little more context to the code? Like maybe a working/breaking demo in JSFiddle? – jmk2142 Commented Jun 27, 2013 at 17:44
1 Answer
Reset to default 1Your BothFieldsIdenticalCaseSensitive function can only work on the fields *passphrase_hidden* and passphrase.
If you wish to check another two fields, then you must create another function for new fields. If, for instance, you created two fields with ids *passphrase_hidden1*, and passphrase1 then you could use this function to validate their input...
function BothFieldsIdenticalCaseSensitive2() {
var two = document.getElementById('passphrase_hidden1').value;
var three = document.getElementById('passphrase1').value;
if(two == three) { return true; }
alert("Warning!! passcodes must match!!!");
return false;
}
another option, that you could try, would be to create one single function and in that function pass the two fields that you want to check like so:
function BothFieldsIdenticalCaseSensitive(fieldId1, fieldId2) {
var two = document.getElementById(fieldId1).value;
var three = document.getElementById(fieldId2).value;
if(two == three) { return true; }
alert("Warning!! passcodes must match!!!");
return false;
}
Edit
You shouldn't reference your fields with this syntax document.bid_deal.passphrase_hidden, not all browsers implement this. The standard way that works across all browsers is to call document.getElementById('passphrase_hidden').
本文标签: Javascript compare and validate two text fieldsStack Overflow
版权声明:本文标题:Javascript compare and validate two text fields - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745311841a2652969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论