• 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: Dependant Fields (variables)

Dependant Fields (variables) 15 years 11 months ago #3375

Hello!

I was wondering if any of you know how to create dependant fields in a form.

For example:

Field 1 values: X, X2, X3.

Field 2 Values (dependant of field 1): > if X was selected then the value is X1
> if X2 was selected then the value is X2.2

and so on...

is there a script that I could use?

thank you...

Mariana.
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 8 months ago #4424

  • vndesign
  • vndesign's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
I want to know to ... Any help from the boss?
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 8 months ago #4426

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
use javascript and insert them into scriptdisplay
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 8 months ago #4690

  • ginius
  • ginius's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
any example?
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 6 months ago #5362

  • allrude
  • allrude's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
any chance of getting a decent anwser or an example so we can use this option ?
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 6 months ago #5410

  • octavian
  • octavian's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
Hello,

First, I've setup 2 fields:
- a dropdown named \"items\". The Items field is filled with:
item1|Item 1 description
item2|Item 2 description
item3|Item 3 description
Additional attributes: onchange=\"get_price(this.value)\"
This dropdown will be the field that other fields will depend on.

- a textbox named \"price\" with an additional attribute: readonly=\"readonly\"
You can however skip this if you want people to be able to write on that field (or if you want to use another field, since the readonly attribute only works for textboxes).

Next, you need to change to the Form Layout tab, disable the Autogenerate layout feature and paste this javascript at the end of the layout:
<script type=\"text/javascript\"> function get_price(what) { var price = 0; switch (what) { case 'item1':[code]
<script type=\"text/javascript\">
function get_price(what)
{
var price = 0;
switch (what)
{
case 'item1':
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:Dependant Fields (variables) 15 years 6 months ago #5481

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
Maybe it is not what he want.
What I mean it is the point 5. of this page :
www.toutjavascript.com/savoir/xmlhttprequest.php3
But it is a small complexe maybe.

So the other solution is :
Have a select field called field 1 for example who have a list.
Have a select field called field 2 for example who have a list dependant from field 1

To filter second select list you have to do :
- First add a hidden field called \"filter_field1\" who is required
- Second add javascript into field 1 for submit on change
- Third add javacript fo insert a value into hidden field if change field 2

Why that ?
On submit, field 2 will be reload, if you have insert custom code with POST value from field 1 it will display new list.
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 6 months ago #5523

Thanks for the wonderfull advise on the subject, but can someone give us a good example on this?
As many others are asking the same thing without a good explanation.
Don't get me wrong but it would be also a good idea if you could add this dropdown list matter in the knowledgebase.

Thank you
I look forward for an answer
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 4 months ago #6145

  • Aeneas
  • Aeneas's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Hi to all!

Has anybody finally solved this issue? I am in the same posistion, cause i want to make the same form, i mean one drop list whose options are dependant from another one. any code?
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 4 months ago #6153

  • Nuta
  • Nuta's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
I solved this problem like this:
First, I've setup 4 fields:
1 a dropdown named \"items\". The Items field is filled with:
Choose the place[c]
Guesthouse
Sanatorium
Your own choice

Additional attributes: onchange=\"hide(this)\"

2&3 Auto-populate lists with items from a table of my DataBase
4 Text field
Additional attributes: style=\"display:none;\"

Put javascript into the Form Layout tab
&lt;script type=\&quot;text/javascript\&quot;&gt;
function hide(what)
{
 if (what.value == 'Choose the place')
{
 document.getElementById('guesthouses').style.display = 'none';
 document.getElementById('sanatorium').style.display = 'none';
 document.getElementById('other').style.display = 'none';
 }
else if (what.value == 'Guesthouses')
 {
 document.getElementById('guesthouses').style.display = '';
 document.getElementById('sanatorium').style.display = 'none';
 document.getElementById('other').style.display = 'none';
 }
  else if (what.value == 'Sanatorium')
 {
 document.getElementById('guesthouses').style.display = 'none';
 document.getElementById('sanatorium').style.display = '';
 document.getElementById('other').style.display = 'none';
 }
 else if (what.value == 'Your own choice')
 {
 document.getElementById('guesthouses').style.display = 'none';
 document.getElementById('sanatorium').style.display = 'none';
 document.getElementById('other').style.display = '';
 }
}
&lt;/script&gt;

The script is working. You can see additional field is dependant from the options of the first one. But when I click \"submit\" nothing happens! I stay at the same page and my hidden fields are hide again. :angry:
So this is just a half of solution :dry: I need an advice too.
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 4 months ago #6154

  • Nuta
  • Nuta's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
I was so stupid :woohoo: It works!
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 4 months ago #6179

  • Aeneas
  • Aeneas's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Congratulations for the script!
I am still trying to make it working...in your example i do not understant the second and third step. what kind of field i have to insert?
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 4 months ago #6188

  • Nuta
  • Nuta's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
It is drop-down field. I used a script from rsjoomla.com \"Auto-populate a list from a table\":
In the \&quot;Items\&quot; are paste the following code:
 
//&lt;code&gt;
$items = \&quot;|Please Select[c]\n\&quot;;
$rez = mysql_query(\&quot;SELECT your_value,your_label FROM your_table_here\&quot;«»);
while($r = mysql_fetch_assoc($rez))
      $items .= $r['your_value'] . '|' . $r['your_label'] . \&quot;\n\&quot;;
return $items;
//&lt;/code&gt;
The administrator has disabled public write access.

Re:Dependant Fields (variables) 15 years 4 months ago #6189

  • Aeneas
  • Aeneas's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Thank you very much! I ´ll give it a try.
The administrator has disabled public write access.

Re:Dependant Fields (variables) 14 years 11 months ago #7453

dragonjc wrote:
Maybe it is not what he want.
What I mean it is the point 5. of this page :
www.toutjavascript.com/savoir/xmlhttprequest.php3
But it is a small complexe maybe.

So the other solution is :
Have a select field called field 1 for example who have a list.
Have a select field called field 2 for example who have a list dependant from field 1

To filter second select list you have to do :
- First add a hidden field called "filter_field1" who is required
- Second add javascript into field 1 for submit on change
- Third add javacript fo insert a value into hidden field if change field 2

Why that ?
On submit, field 2 will be reload, if you have insert custom code with POST value from field 1 it will display new list.

Hi everyone,

Who has an example on how to do this?

Thx in advance

Beertje_007
The administrator has disabled public write access.

Re:Dependant Fields (variables) 13 years 6 months ago #11872

  • shadman
  • shadman's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Dear Nuta
i can't solve this problem , may you upload your Form backup , i confused !!
i want depend 2 dropdown to each other but i can't
thanks
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!