Hello:
Could someone help me to join the following two codes? I'm a PHP/MySQL programmer but have no experience with Javascript coding. I've tried various combinations and have read some online Javascript tutorials but I cannot figure out how to create a code to dynamically format information typed into an input field and have it transfer to another input field on 'onkeyup.'
Here's what I have so far for copying the data from one input field to another:
<form name="test">
<p>First Name: <input type="text" name="Afname" onkeyup="copy()"></p>
<p>First Name: <input type="text" name="Bfname"></p>
</form>
<script type="text/javascript">
function copy()
{
document.test.Bfname.value = document.test.Afname.value;
}
</script>
And here's what I found online to do the formatting:
<script type="text/javascript">
// Store the current title value
var title = 'This is a title with a symbol &'
// alert(title); // debug
// Clean up the title
var url
.toLowerCase() // change everything to lowercase
.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces
.replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
.replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
.replace(/^-+|-+$/g, ""); // trim leading and trailing hyphens
alert(url); // outputs 'this-is-a-title-with-a-symbol'
</script>
The second code is exactly what I need (see comments) but I don't know how to format the first code to work with the second one. There are scripts online that do this but only after clicking on the submit button. I don't want to click on a submit button. I want the script to work dynamically and format the input field data as I type. Can this be done?
Can someone please help?
Thank you!