How to add a value in front of a field?
How to add a value in front of a field?
I have an editor table and when I add a new product, I want to be able to ensure that the customer code is added at the beginning of any product id.
Right now when I add a new product, I have a product id field. I want to prefix whatever is typed in this field by the user with the PHP $_SESSION['customercode'] (Example: MJK-).
I can pre-populate the field with this code as the "def:" value but the user could easily delete the text.
Is there a way to prevent the text default value from being deleted or is there some way to pre-prend the text to the field using preSubmit?
Any help would be appreciated.
This question has an accepted answers - jump to answer
Answers
So I came up with a solution.
First, in the PHP page, I call the JS file using the following syntax (I add the ?version=1 so that the JS file won't be cached changing the number before each test) :
At the top of the JS file, I have the following code to retrieve the SESSION variable:
Then I add the following after the editor code:
Just an update, I added the following wrapper inside the preSubmit so it only performs the concatenation on create and not edit or remove:
Yep, that's a good way to go.
Colin