Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Select Menu making selected text stick...
Old 11-22-2012, 10:35 PM Select Menu making selected text stick...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Hi All,

I am not too sure if this is going to have a php solution or something simple in html, but here goes:

I have a drop down (select) menu, and have some choices of course, now when I select one, the page loads (using onchange event handler no button)...What I would like to know how to do is keep the selected choice as the default value, so let's say I have a default value currently as Choose an option, and I click option 1, how can I have the default value say option 1 instead of Choose an option as it currently stands?

Update, I tried using the following php code which does work on this, but when I apply it to my select menu, it defaults to the original default choice so I am wondering if this code could be modified to my needs:

PHP Code:
<select name="categories">
<option value="">Choose a category...</option>
<option value="seo" <?php echo $result['categories'] == 'seo' 'selected' ''?> >Search Engine Optimization</option>
<option value="auto" <?php echo $result['categories'] == 'auto' 'selected' ''?>>Autos</option>
<option value="business" <?php echo $result['categories'] == 'business' 'selected' ''?>>Business</option>
<option value="design" <?php echo $result['categories'] == 'design' 'selected' ''?>>Design</option>
Hope that explains it!

Thank you, and Happy Thanksgiving!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 11-23-2012 at 12:09 AM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-23-2012, 10:41 AM Re: Select Menu making selected text stick...
chrishirst's Avatar
Defies a Status

Posts: 43,970
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Step through a foreach loop
something like
PHP Code:
<?php
$categories 
= array(
    
'seo' => 'Search Engine Optimization',
    
'auto' => 'Autos',
    
'business' => 'Business',
    
'design' => 'Design',
);
?>


<select name="categories">
<?php foreach( $categories as $var => $categories ): ?>
<option value="<?php echo $var ?>"<?php if( $var == $result['categories'] ): ?> selected="selected"<?php endif; ?><?php echo $categories?></option>
<?php endforeach; ?>
</select>
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 11-23-2012 at 10:44 AM..
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-23-2012, 05:12 PM Re: Select Menu making selected text stick...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Hi Chris,

That appears to work for me, but...The only way I can tell for sure, is I am going to have to target the links into the same page frame, because when the links open in a new window, and I hit back in the browser, it's natural for the drop down to stay put, on the selected choice, so I now have to figure out whether to use a php switch or iframe, or something else maybe? This would be the actual intention in my case (to load the content into the same page). What do you think for this case? A php switch statement like:


HTML Code:
<table width="200" border="1">
  <tr>
    <td>
PHP Code:
<?
switch ($_GET['page']) 
{
case 
"main": include '1.php'; break;
case 
"2": include '2.php'; break;
case 
"3": include '3.php'; break;


default: include 
'1.php'; break;

}
?>
HTML Code:
</td>
    <td><a href="index.php?page=main">page1</a><br /><a href="index.php?page=2">page2</a><br /><a href="index.php?page=3">page3</a><br /></td>
  </tr>
</table>
or a basic iframe...What do you think? I am going to mess with the above code to see if I can manage getting the drop down links to use that code.
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 11-23-2012 at 05:17 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-23-2012, 05:57 PM Re: Select Menu making selected text stick...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
I think I jumped to far ahead of myself, what I need to do first, is determine whether to use the iframe or the above switch statement to target the links in the drop down, then use your code Chris, to make the drop down option 'stick'...
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-23-2012, 06:33 PM Re: Select Menu making selected text stick...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Quote:
Originally Posted by chrishirst View Post
Step through a foreach loop
something like
PHP Code:
<?php
$categories 
= array(
    
'seo' => 'Search Engine Optimization',
    
'auto' => 'Autos',
    
'business' => 'Business',
    
'design' => 'Design',
);
?>


<select name="categories">
<?php foreach( $categories as $var => $categories ): ?>
<option value="<?php echo $var ?>"<?php if( $var == $result['categories'] ): ?> selected="selected"<?php endif; ?><?php echo $categories?></option>
<?php endforeach; ?>
</select>
Chris,

I think I am on to something...But I need to know about something in the array you posted:

PHP Code:
<?php
$categories 
= array(
    
'seo' => 'Search Engine Optimization',
    
'auto' => 'Autos',
    
'business' => 'Business',
    
'design' => 'Design',
);
?>
Does 'seo' , 'auto' 'business' 'design' represent the option name and 'Search Engine Optimization', 'Autos', 'Business', 'Design' represent the option value or vice versa? I am a bit lost there.

Thanks
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-23-2012, 06:49 PM Re: Select Menu making selected text stick...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
I tried using both the option name and option values.

Regardless of what I tried, I couldn't keep the selected option to stick...

Here's all the code I have:

To target the drop down links into the iframe:

HTML Code:
<script type="text/Javascript">
function jumpMenu(targ,selObj,restore)
{
var url = selObj.options[selObj.selectedIndex].value;    
selObj.options[selObj.selectedIndex].value +"'");
var iframe = document.getElementById('test');
iframe.src = url;
if (restore) selObj.selectedIndex=0;
}
HTML Code:
<select name="categories" id="categories" onchange="if(this.value!=''){document.location.href=this.value}" alt="Reunite My Site - Drop Down Navigation" title="Reunite My Site - Drop Down Navigation">

<!-- PHP Loop To Keep Current Select Option Selected -->

<?php foreach( $categories as $var => $categories ): ?>
<option value="<?php echo $var ?>"<?php if( $var == $result['categories'] ): ?> selected="selected"<?php endif; ?>> <?php echo $categories?></option>
<?php endforeach; ?>

<option value="Categories/Choice1" >Choice1</option>
<option value="Categories/Choice2">Choice2</option>
<option value="Categories/Choice3">Choice3</option>
<option value="Categories/Choice4">Choice4</option>
</select>
Then finally the iframe tag:
HTML Code:
<iframe src="" id="test">
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-23-2012, 08:03 PM Re: Select Menu making selected text stick...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
I have decided to use the php switch statement due to browser compatiblity issues / with the iframe tag...Anyway...I need to know how I can open a url in a different folder from that script:

ex: I need to use this type of url: <a href="index.php?page=path/to/index.php">page2</a>

And currently it only works if the file is in the current folder. How can I get it so I can view pages in other folders on the server using the above url?

Scratch this...I FORGOT I CAN USE PHP Includes for that! SORRY about that one!

Thanks again!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 11-23-2012 at 08:11 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-24-2012, 10:17 AM Re: Select Menu making selected text stick...
chrishirst's Avatar
Defies a Status

Posts: 43,970
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
 <?php
$categories = array(
    'seo' => 'Search Engine Optimization',
    'auto' => 'Autos',
    'business' => 'Business',
    'design' => 'Design',
);?>
It is a associative array. A two dimensional array referenced by the key name rather than the index number, the first entry is the key ie 'seo' which is used for the option value attribute, the second entry is the key value used for the option text.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Select Menu making selected text stick...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31041 seconds with 11 queries