Hi all,
I'm trying to use replace to remove ' ' characters from a variable and having no luck whatsoever.
What I'm trying to do is take an indented drop-menu and apply an onChange event handler so that when someone selects an item from the menu the indentation is removed and the text that's left is placed in a separate text field. It does this so that the text in the text field can be edited and then updated in my database so that menu item names can be changed.
It's all working fine except the indentation isn't being removed. I know I can remove it server side in my script there, but it looks messy client side to have the leading spaces.
Here's my code, any help would be great!
Code:
<SCRIPT TYPE="text/javascript">
function selectItem(cat_id, cat_value){
var option_name = document.getElementById(cat_id);
var option_count = option_name.length;
var option_value = document.getElementById(cat_id).value;
for(i = 0; i < option_count; i++){
if(option_name[i].value == option_value){
return_text = option_name[i].text;
document.getElementById(cat_value).value = return_text.replace(/ /gi,'');
}
}
return false;
}
</script>
And here are the select box and text fields in question.
Code:
<select name="parent_id" id="select_cat" onChange="selectItem('select_cat','cat_edit');">
<option value="1">Programming</option>
<option value="2"> PHP</option>
<option value="4"> Tutorials</option>
<option value="7"> Scripts</option>
<option value="3"> ASP</option>
<option value="8"> JavaScript</option>
<option value="5">Design</option>
<option value="6"> Graphic Design</option>
<option value="9"> Web Design</option>
</select> Select category to edit<br /><br />
<input type="text" name="title" id="cat_edit" /> Edit category<br />