SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Drop Down Value

  1. #1
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Drop Down Value

    In a drop down you have this:

    <select name="something">
    <option value="value">First Selection</option>

    The question is I have a popup window that comes up to add a new shop. Now once the shop is added I want to close the window and then place the shops name and shop id in the drop down. I understand how to close the window and add the value to the box. But how do you have the name you want go between the <option>Want name here</option> part

    Thanks
    Silly

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    see the "Adding Options from a Child Window" script/tutorial at my site

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean changing the text inside the options if so take a look at this example!

    Code:
    <html>
    <head>
    <script>
    function changeSelectBox(){
    var ln=document.theFrm.opt.options.length;
    var op=[];
    for(i=0;i<ln;i++){
    op[i]=document.theFrm.opt.options[i].text;
    }
    op.reverse();
    for(i=0;i<ln;i++){
    document.theFrm.opt.options[i].text=op[i];
    }
    }
    
    
    
    </script>
    </head>
    <body>
    <form name="theFrm">
    <select name="opt">
    <option>option1</option>
    <option>option2</option>
    <option>option3</option>
    <option>option4</option>
    <option>option5</option>
    <option>option6</option>
    </select>
    <input type="button" value="change me" onclick="changeSelectBox();">
    </form>
    </body>
    </html>
    use the .text! document.formName.selectElement.options[index].text;

    Good Luck!

    Jon!

  4. #4
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Poop_Shoot
    Do you mean changing the text inside the options if so take a look at this example!
    Code:
    <html>
    <head>
    <script>
    function changeSelectBox(){
    var ln=document.theFrm.opt.options.length;
    var op=[];
    for(i=0;i<ln;i++){
    op[i]=document.theFrm.opt.options[i].text;
    }
    op.reverse();
    for(i=0;i<ln;i++){
    document.theFrm.opt.options[i].text=op[i];
    }
    }
    
    
    
    </script>
    </head>
    <body>
    <form name="theFrm">
    <select name="opt">
    <option>option1</option>
    <option>option2</option>
    <option>option3</option>
    <option>option4</option>
    <option>option5</option>
    <option>option6</option>
    </select>
    <input type="button" value="change me" onclick="changeSelectBox();">
    </form>
    </body>
    </html>
    use the .text! document.formName.selectElement.options[index].text;

    Good Luck!

    Jon!
    What I was looking for is when filling out a form I click on a button that says add a shop. A javascript window pops open a form to add a shop. Once I click add I want it to add the shop to the db, which it already does, and then close out of the window going back to the previous form.

    Once there the javascript passes the shop id and the shop name that the person just added to the drop down in the previous form and populates the value of the drop down and the name of the dropdown. So for example:

    I just added a shop called Bobs Shop. It has a idea of 5. The second I click close the window closes and passes the information back to the previous form I clicked the add shop link from and now the drop down menu for shops should look like this code wise:

    <option value="5"> Bobs Shop</option>

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sillysoft,

    Did you check out the script? The child window uses checkboxes (if I remember right), and then passes the selected info to the selection list in opener.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •