use onchange to rename select

Posted on 2006-03-22
Last Modified: 2011-10-03
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>

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.
Question by:juven14
    LVL 49

    Expert Comment

    Only thing I would know is to use:

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

    But why do you need to change the name anyhow?


    Author Comment

    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?

    <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>

    I can't use the value field so I'm guessing that it is possible to switch the name with the option id value.
    LVL 49

    Accepted Solution

    I think you can use":

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



    Author Comment

    Thanks, this worked perfect.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now