I have the following function that replaces part of a string so that the following:
AA – Test – AA
Becomes:
Test – AA
What I would like is for the function to change the string so it becomes just
Test
Can anyone help?
Thanks.
AA – Test – AA
Becomes:
Test – AA
Code:
function Add () {
var selObj = document.getElementById('Test1');
var txtObj = document.getElementById('Test2');
var selIndex = selObj.selectedIndex;
var txt = txtObj.value;
[COLOR=red]txtObj.value = selObj.options[selIndex].text.replace(/\w+[- ]+/,''); [/color]
}
What I would like is for the function to change the string so it becomes just
Test
Can anyone help?
Thanks.