0

I am new to javascript and I can see this being a really easy request but I cannot figure it out.

I have a simple html form with consists of two fields, Name and Email.

When the form is submitted, I want to create a unique ID based on the input name and then submit the form along with the new unique ID. The form is submitted to a webhook.

so far I have the following:

HTML:

<form
  id="myForm"
  action="https://hook.integromat.com"
  type="POST"
>
<input type="text" name="full-name" id="name" placeholder="What's your name?" />
<input
type="email"
name="email-address"
placeholder="What's your email address?"
/>
  <input type="submit" value="Submit" id="Form-submit" />
</form>

Javascript:

    function myFunction(){
        let InputName = document.getElementById('name').value
        
        
        function CreateBasename(InputName) {    
        // Change Case - START    
        const toCapitaliseCase = (phrase) => {    
            return phrase    
            .split(' ')    
            .map(word => word.charAt(0).toUpperCase() + word.slice(1))    
            .join(' ');        
        };    
        let Capitalise = toCapitaliseCase(InputName);        
        // Change Case - END    
        // return capitalise; // The ABC Company
                
        // Format Client Name if starts with 'The' - START  
        if (Capitalise.startsWith('The ')) { //The ABC Company    
            let Words = Capitalise.split(' '); //["The","ABC","Company"]    
            let The = Words[0]; // The    
            let TheSlice = Capitalise.slice(4); //ABC Company    
            let Comma = ', '; // ,    
            let BaseName = TheSlice.concat('', Comma, The); // ABC Company, The    
            return BaseName //ABC Company, The    
        }    
        // Format Client Name if it DOESN'T start with 'The' - START    
        else { //The ABC Company        
            return Capitalise    
        }  
        }
        var BaseName = CreateBasename(InputName);
        
        
        document.getElementById('demo').innerHTML = BaseName
        return true;
        
        } 
        

I just can't workout how to get the new value to be included into the form so I can send it.

Juan-man
  • 174
  • 8

1 Answers1

0

Just add a <input type="hidden" name="unique-id"> and populate it with your js logic right before submitting the form.

dfvc
  • 316
  • 1
  • 5