• 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: Dynamic Dropdown populates textbox based on select

Dynamic Dropdown populates textbox based on select 9 years 10 months ago #31415

So I've got a form that has supplier names and supplier numbers. When a form is filled out a Supplier name is picked from a dropdown which is populated from the database using the dynamic dropdown code. Now I need the Supplier number to populate automatically from the selection in the dropdown. I'm not using the default way of setting the values. I'm actually querying them from the table rsform_submission_values. here's the code I have in my dropdown value section
//<code>
$items = array();
$db = JFactory::getDbo();
$items[] = "|Please Select[c]";
$db->setQuery("SELECT FormId,FieldName,FieldValue FROM XXXXXX_rsform_submission_values WHERE FormId = '5' and FieldName = 's_name' ORDER BY FieldValue");
$results = $db->loadObjectList();
 
foreach ($results as $result) {
  $value = $result->FormId;
  $label = $result->FieldValue;
  $items[] = $value.'|'.$label;
}
 
$items = implode("\n", $items);
 
return $items;
//</code>

Now I need to figure out how to add an ONCHANGE attribute to update the textbox.. Any Ideas? the names for the fields are sup_name and sup_num
The administrator has disabled public write access.

Dynamic Dropdown populates textbox based on select 9 years 10 months ago #31433

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
You can add an onchange attribute to the textbox by clicking EDIT and in the Addition Attribute, add it like this:

onchange="myFunction();"
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

Dynamic Dropdown populates textbox based on select 9 years 9 months ago #31755

Thanks for the reply, I had moved on and just now coming back to this. So if I were to use ajax to update the value in the textbox do I need to write a seperate script file and call it or can I add the php script in one of the php script text boxes in the rsform properties menu,And how would I call it if I did.

example code below
 
$.ajax({
    type: 'GET',
    url: '[b][color=#ff0000]WHAT WOULD I CALL HERE????[/color][/b]',
    timeout: 2000,
    success: function(data) {
      $("#content").html(data);
      myFunction();
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      alert("error retrieving content");
    }
 
 


trying to figure out how to call the URL, and if I can call one of the php script boxes instead.

edit, just notices the bold and color didn't work for my highlight. Anyhow it's in the URL where I'm having the problem.
Last Edit: 9 years 9 months ago by timeforaction.
The administrator has disabled public write access.

Dynamic Dropdown populates textbox based on select 9 years 9 months ago #31758

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Easiest approach would be to add the the PHP Script (to query the database) in the PHP Scripts called on form display.

Basically, you will have to create a script that looks something like this:
// Due to the fact that you don't want to run the script everytime your form displays, it would be best to send the request through a URL parameter, e.g. "action"
$action = JRequest::getWord('action');
if ($action == "populate") {
 // Start your code here
}

The url that you use for AJAX call will be the URL to your Form with the new added parameter. e.g.
...index.php?option=com_rsform&formId=1&action=populate
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

Dynamic Dropdown populates textbox based on select 9 years 9 months ago #31764

Thank you so much for a quick reply, I'd never figured that out. Going to jump on it today and see if I can make this work. Again 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!