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
Add a ment  | 

1 Answer 1

Reset to default 1

Your 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