• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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.
0
juven14
Asked:
juven14
  • 2
  • 2
1 Solution
 
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
 
RoonaanCommented:
I think you can use":

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

-r-

0
 
juven14Author Commented:
Thanks, this worked perfect.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now