• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: How to compare two fields using Javascript

How to compare two fields using Javascript 16 years 2 months ago #6608

I could not get the script working in the sample script section so changed it to the one below
<script type="text/javascript">
function checkEmail(theForm) 
{
var email1 = document.getElementById('email1').value;
var email2 = document.getElementById('email2').value;
if (email1 != email2)
{
  alert('Not Equal!');
  return false;
}
else
{
  return true;
}
}
</script>
Last Edit: 16 years 2 months ago by ian.scott.
The administrator has disabled public write access.

Re:How to compare two fields using Javascript 16 years 2 months ago #6728

Hi there. I too, am having an issue that even this variation hasn't addressed.

This is my specific code catering to email fields:
<script type="text/javascript">
function checkEmail(theForm)
{
var email1 = document.getElementById('email1').value;
var email2 = document.getElementById('email2').value;
if (email1 != email2)
{
alert('Not Equal!');
return false;
}
else
{
return true;
}
}
</script>

using the
onclick="return checkEmail(this);"

in my submit attribute field.

Is there specific placement this script needs to be implemented within the 'Form Layout'?

Thank you for your assistance,

Kitty
Kitty
AIM: freeredmcgee
Email: This e-mail address is being protected from spambots. You need JavaScript enabled to view it
The administrator has disabled public write access.

Re:How to compare two fields using Javascript 16 years 2 months ago #6729

  • bogdan
  • bogdan's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 122
  • Thank you received: 4
Hello,

Put this script in the Form Layout
<script type="text/javascript">
function checkEmail(email1,email2)
{
var e1 = document.getElementById('email1').value;
var e2 = document.getElementById('email2').value;
if (e1 != e2)
{
alert('Not Equal!');
return false;
}
else
{
return true;
}
}
</script>

and set the additional attribute of the submit button to
onclick=" return checkEmail('email1','email2');"
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here

RSJoomla! Development Team
The administrator has disabled public write access.

Re:How to compare two fields using Javascript 16 years 2 months ago #6730

Beautiful, thank you!
Attachments:
Kitty
AIM: freeredmcgee
Email: This e-mail address is being protected from spambots. You need JavaScript enabled to view it
The administrator has disabled public write access.

Re:How to compare two fields using Javascript 15 years 1 month ago #10002

  • patrick.jackson2
  • patrick.jackson2's Avatar
  • OFFLINE
  • Fresh Boarder
  • KPS - Joomla Consultant Melbourne Australia
  • Posts: 12
  • Thank you received: 6
Just for those looking at doing this on a longer form, you can trigger the validation sooner than at the Submit button stage.

Start by following this custom scripting tip to set up your Javascript and then the two fields.
www.rsjoomla.com/customer-support/docume...sing-javascript.html

But instead of in the third part where you add the onclick value to the Submit button, do the following:

- go to the attributes field for email2
- paste the following:
onblur="return checkEmail(this);"
- this will then do the validation when you exit the second email field, instead of waiting until the form has been submitted!
The administrator has disabled public write access.
The following user(s) said Thank You: illuminatus

Re:How to compare two fields using Javascript 13 years 10 months ago #13981

patrick.jackson2 wrote:
Just for those looking at doing this on a longer form, you can trigger the validation sooner than at the Submit button stage.

Start by following this custom scripting tip to set up your Javascript and then the two fields.
www.rsjoomla.com/customer-support/docume...sing-javascript.html

But instead of in the third part where you add the onclick value to the Submit button, do the following:

- go to the attributes field for email2
- paste the following:
onblur="return checkEmail(this);"
- this will then do the validation when you exit the second email field, instead of waiting until the form has been submitted!

add this code to empty the email2 field upon clicking ok on the alert so the end user will not be able to continue without entering a matching email address:

document.getElementById('email2').value = "";

so the code should be:

<script type="text/javascript">
function checkEmail() {
if (document.getElementById('email1').value != document.getElementById('email_confirm').value)
{
alert('Those emails don\'t match!');
document.getElementById('email2').value = "";
return false;
}
else {
return true;
}
}
</script>


Thx
The administrator has disabled public write access.
The following user(s) said Thank You: illuminatus
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!