Jump to content

javascript on Submit in popup to update drop down field in another datapage


Recommended Posts

Hello,

I'm using some code in the Destination section of a  submission datapage, deployed in a popup, to update a dropdown field in another datapage. I can get it to work if the dropdown field is a simple text field (store and display the same field) but am having issues when the dropdown is set to store the Unique ID (integer field) but display a different text field.

The purpose of the popup is for the user, when creating an inventory item on one datapage,  to be able to add a new 'supplier' for it on the fly in another datapage. When the new 'supplier' is submitted, it's ID value goes to the 'supplier' field dropdown on the original datapage and is added to the available lookup choices.

The problem is that this code will put the new Unique ID (the SupplierID) in the the dropdown's 'display' so the user sees the ID number instead of the supplier name they typed in on the popup datapage. That new supplier name (text field) is what I need to 'display' in the drop down field BUT use the uniqueID as the 'stored' value. 

Also, I normally would use a trigger and a field for quick entry (the Supplier's table is different than the Inventory Items table) that could do all this behind the scenes. However, that table is locked by Caspio because of other backend triggers so I have to do this with datapages. 

Here's the code I'm using. Again, I need to 'display' the Supplier_Name (text255) value but 'store' the SupplierID (integer) when it's sent to the dropdown in the other datapage. Any help would be really appreciated!

<script>

window.close();

//Replace the FieldName with the Submission form FieldName(parameter name passed when you checked “on exit”.

var element_value='[@InsertRecordSupplierID]'

var new_item = window.opener.document.createElement("option");

new_item.text=element_value;

new_item.value=element_value;

// Add new item to the dropdown

 try

{

//Replace the FieldName with the Original DataPage dropdown FieldName

window.opener.document.getElementsByName("InsertRecordSupplierID")[0].options.add(new_item, null);

}

catch(ex)

{

//Replace the FieldName with the Original DataPage dropdown FieldName

window.opener.document.getElementsByName("InsertRecordSupplierID")[0].options.add(new_item);

}

</script>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...