How to transform data from a HTML form field and display it on another field?

I am not at all experienced with Javascript, so I don’t really know what I am doing.

Here is the description of what I am trying to do:

I have a form with 2 fields (field1 and field2). The user will enter a value into field1 (i.e. Jim’s Stuff). I now want to transform this text, by making it all lower case, changing the spaces to dashes, and to remove many special characters, such as brackets, periods and apostrophes. The remaining result I then want to be displayed in field2, provided that field2 is blank (i.e. jims-stuff)

With a bit of help from someone else, I here is the code I currently have to work with. The problem though, is since I don’t know what I am doing, I don’t know how to change the value from field1 (an HTML element) to a javascript string, that I can then do my transformation/replacements, and them convert back to an HTML element.

Could someone please help me with this:

You see how you are checking if field2 is empty:

field2.value === ''

The value property gets the current value, or text, that is in field2. So if you want to modify the value, or text that is in field1 then you would need to access it the same way, with the value property.

That works great now. Thank you for your help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.