I have a custom js file in my custom module, which generates a 3-digit ID,
function genDigit() {
return Math.floor(Math.random()*899+100);
}
I would like to add this ID in my webform as follows:
- When a user opens a webform page in the browser, the js is called from the custom module (assuming the module is active)
- The generated ID is passed automatically to the webform in a hidden field
- When submitting the form, the ID is saved as well alongside the other data.
I would suggest something like this:
Whereby you put the js in the drupal_add_js function itself, instead of calling an external js file to do so. By the way this function does not generate a unique ID, but can give you an idea how to proceed from here.
But the idea of adding such ID to a webform is indeed curious, as any webform has a unique ID already as @CornelAndreev mentioned earlier. Good luck.