SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing select menu options

    Hi all,

    I'm trying to change some code here. It involves Smarty Templates...
    I believe (actually, I hope) my problem is stemming from the javascript on the page.

    Code for Location 1:

    HTML Code:
    <p>
    <label for="fullname">
    Location Type<span class="required">*</span>:</label>
    <select name="location1type" onChange="redirect(this.options.selectedIndex)">
    <option value="hotel" {if $data.location1type eq "hotel"}selected{/if}>Hotel</option>
    <option value="location" {if $data.location1type eq "location"}selected{/if}>Location</option>
    </select>
    </p>
    
    <p>
    <label for="fullname">
    Location 1<span class="required">*</span>:</label>
    <select name="location1">
    {if $data.location1type eq "location"}
    <option value="">---------- select a location ----------</option>
    {section name=item loop=$locations}
    <option value="{$locations[item].location_code}" {if $locations[item].location_code eq $data.location1}selected{/if}>{$locations[item].location_desc}</option>
    {/section}
    {else}
    <option value="">---------- select a hotel ----------</option>
    {section name=item loop=$hotels}
    <option value="{$hotels[item].hotel_num}" {if $hotels[item].hotel_num eq $data.location1}selected{/if}>{$hotels[item].hotel_name}</option>
    {/section}
    {/if}
    </select>
    </p>
    
    <script language="JavaScript">
    <!--
    
    var group=new Array(2)
    for (i=0; i<2; i++)
    group[i]=new Array()
    
    group[0][0]=new Option("---------- select a hotel ----------","")
    {section name=item loop=$hotels}
    group[0][{$smarty.section.item.iteration}]=new Option("{$hotels[item].hotel_name}", "{$hotels[item].hotel_num}")
    {/section}
    
    group[1][0]=new Option("---------- select a location ----------","")
    {section name=item loop=$locations}
    group[1][{$smarty.section.item.iteration}]=new Option("{$locations[item].location_desc}", "{$locations[item].location_code}")
    {/section}
    
    var temp=document.Reservations.location1
    
    function redirect(x){ldelim}
    for (m=temp.options.length-1;m>0;m--)
    temp.options[m]=null
    for (i=0;i<group[x].length;i++){ldelim}
    temp.options[i]=new Option(group[x][i].text,group[x][i].value)
    {rdelim}
    temp.options[0].selected=true
    {rdelim}
    
    //-->
    </script>
    Code for Location 2:
    HTML Code:
    <p><label for="fullname">
    Location 2 type<span class="required">*</span>:</label>
    <select name="location2type" onChange="redirect(this.options.selectedIndex)">
    <option value="hotel" {if $data.location2type eq "hotel"}selected{/if}>Hotel</option>
    <option value="location" {if $data.location2type eq "location"}selected{/if}>Location</option>
    </select></p>
    
    <p><label for="fullname">
    Location 2<span class="required">*</span>:</label>
    <select name="location2">
    {if $data.location2type eq "location"}
    <option value="">---------- select a location ----------</option>
    {section name=item loop=$locations}
    <option value="{$locations[item].location_code}" {if $locations[item].location_code eq $data.location2}selected{/if}>{$locations[item].location_desc}</option>
    {/section}
    {else}
    <option value="">---------- select a hotel ----------</option>
    {section name=item loop=$hotels}
    <option value="{$hotels[item].hotel_num}" {if $hotels[item].hotel_num eq $data.location2}selected{/if}>{$hotels[item].hotel_name}</option>
    {/section}
    {/if}
    </select>
    </p>
    
    <script language="JavaScript">
    <!--
    
    var group=new Array(2)
    for (i=0; i<2; i++)
    group[i]=new Array()
    
    group[0][0]=new Option("---------- select a hotel ----------","")
    {section name=item loop=$hotels}
    group[0][{$smarty.section.item.iteration}]=new Option("{$hotels[item].hotel_name}", "{$hotels[item].hotel_num}")
    {/section}
    
    group[1][0]=new Option("---------- select a location ----------","")
    {section name=item loop=$locations}
    group[1][{$smarty.section.item.iteration}]=new Option("{$locations[item].location_desc}", "{$locations[item].location_code}")
    {/section}
    
    var temp=document.Reservations.location2
    
    function redirect(x){ldelim}
    for (m=temp.options.length-1;m>0;m--)
    temp.options[m]=null
    for (i=0;i<group[x].length;i++){ldelim}
    temp.options[i]=new Option(group[x][i].text,group[x][i].value)
    {rdelim}
    temp.options[0].selected=true
    {rdelim}
    
    //-->
    </script>
    These are on the same page. I want to be able to change Location 1 based on the Location 1 Type selected. However, when I change Location 1 Type, it changes my Location 2 options instead of Location 1. I've changed the names, as much as I can tell, to match form names/elements but it's not done any good.

    Thanks for any help!
    No, I REALLY dislike having to use Joomla.

  2. #2
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing?
    No, I REALLY dislike having to use Joomla.

  3. #3
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm assuming it's this that causes the change.

    Code:
     onChange="redirect(this.options.selectedIndex)"
    I've changed this line from:
    Code:
    var temp=document.Reservations.location2
    to:
    Code:
    var temp=document.Reservations.location1
    When both lines say .location1, the location 1 changes. When one says .location1 and the other says .location2, location1type changes location2 instead of location1.

    There's gotta be a way to trigger the first javascript code with that redirect without triggering the second javascript code.?????
    No, I REALLY dislike having to use Joomla.


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
  •