• 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: Required (filled) first OR second textbox

Required (filled) first OR second textbox 13 years 6 months ago #11896

  • au9879
  • au9879's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Hello!

I got two textboxes, I want that at least one of them is filled.

How do I do that? I know it cant be a complicated solution, but still some help maybe?

Thank you
The administrator has disabled public write access.

Re:Required (filled) first OR second textbox 13 years 6 months ago #11899

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Hello,

The easiest solution would actually be to make one of the required.

If this isn't the case... you can achieve this with a rather simple Javascript, placed on the CSS/Javascript tab. For example:
<script type="text/javascript">
function verify()
{
if(document.getElementById('name_of_first_field').value == '' && document.getElementById('name_of_second_field').value == '')
{
alert("Please fill in at least one of the two fields");
return false;
}
return true;
}
</script>

On the Additional Attributes area of the submit button you will have to trigger the function:
onclick="return verify();"
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re:Required (filled) first OR second textbox 13 years 6 months ago #11900

  • au9879
  • au9879's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Firstly thank you for your quick help.

I tried your sollution, but the form is always send, even if both fields are empty! Your code looks good, I cant find any mistakes myself. This is what I did:
- I coppied your code into tab "Form Layout" (before the rest of code), Auto Generate Layout is OFF! I changed the "name_of_first_field" and "name_of_second_field" to match MY field names.
- I changed "Additional Attributes" area of the submit button to onclick="return verify();"

I also tried coppied your code (with my field names) into "Scripts" tab under "Script called on form process".

The form is always send, even if both fields are empty. Did I make some mistake (where is the "CSS/Javascript tab" you mentioned?)

Thanx again!
The administrator has disabled public write access.

Re:Required (filled) first OR second textbox 13 years 6 months ago #11901

  • au9879
  • au9879's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
I am so stupid :( Your solution works just fine, but I written my textfield name wrong (without a caps on one letter) :blush: It is interesting that if you put not existing textfild name into your function, that value of that not existing textfild is not empty.

Im so sorry again and thank you for your great help!
The administrator has disabled public write access.
  • 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!