use onchange to rename select

I have a select:

<select name="type" id="type">
  <option value="1">Name</option>
  <option value="2">Name</option>
  <option value="3">Name</option>
  <option value=''ALL">All</option>
</select>

How can I change the name from type to othertype by the user selecting all.

I have tried onchange but my knowledge of javascript is extremely poor.
juven14Asked:
Who is Participating?
 
RoonaanCommented:
I think you can use":

<select name="type" onchange="this.name=this.options[this.selectedIndex].id" >

-r-

0
 
RoonaanCommented:
Only thing I would know is to use:

<select name="type" id="type" onchange="this.name='othertype';">

But why do you need to change the name anyhow?

-r-
0
 
juven14Author Commented:
I have a list of subcategories that are used to search a subcategory field and have another field that searches all categories.

Cateogory Parent
1               0
2               1
3               0
4               2
5               1


The search looks for categories via:

select name = type
 category like% type
I have added another field that will search by parent, ie select name=parent
 parent like% parent

How can I get a value from the option to change the name?
I.e.

<select name=type>
<option value=1 id=type>subcategory 1</option>
<option value=2 id=type>subcategory 2</option>
<option value=1 id=parent>ALL</option>
</select>

I can't use the value field so I'm guessing that it is possible to switch the name with the option id value.
0
 
juven14Author Commented:
Thanks, this worked perfect.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.