Jump to content

retaingin pulldown value


wkilc

Recommended Posts

<?php
if(isset($_GET['selected']) && !empty($_GET['selected'])) {
if($_GET['selected'] == 'maple') {
$selected = 'selected'
}
} else {
$selected = '';
}
?>
<form>
<select name="trees">
<option value="maple" <?=$selected?>>maple</option>
<option value="oak">oak</option>
<option value="pine">pine</option>
</select>
</form>

 

do that for all 3 of em, using a switch would be better.

 

Regards ACE

Assuming your form is posting to itself....

 

<form method="post" action="">
 <select name="trees">
   <option value="maple"<?php echo (isset($_POST['trees']) && $_POST['trees'] == 'maple') ? ' selected="selected"' : ''; ?>>maple</option>
   <option value="oak"<?php echo (isset($_POST['trees']) && $_POST['trees'] == 'oak') ? ' selected="selected"' : ''; ?>>oak</option>
   <option value="pine"<?php echo (isset($_POST['trees']) && $_POST['trees'] == 'pine') ? ' selected="selected"' : ''; ?>>pine</option>
 </select>
</form>

Thank you.

 

I'm still having trouble, as my form is more complicated than my example.  This is what I've got... no errors, but it's not working to hold the value:

 

<select name="link">
<option value="<? echo "$page_name" ?>&limit=25"<?php echo (isset($_POST['link']) && $_POST['link'] == '$page_name&limit=25') ? ' selected="selected"' : ''; ?>>25</option>
<option value="<? echo "$page_name" ?>&limit=50"<?php echo (isset($_POST['link']) && $_POST['link'] == '$page_name&limit=50') ? ' selected="selected"' : ''; ?>>50</option>
</select>

 

Thank you again.

 

~Wayne

Thank you once again!

 

The code now reads:

 

<select name="link">
<option value="<? echo $page_name ?>&limit=25"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=25") ? ' selected="selected"' : ''; ?>>25</option>
<option value="<? echo $page_name ?>&limit=50"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=50") ? ' selected="selected"' : ''; ?>>50</option>
</select>

 

But the list still defaults to the first value... and when I view the processed source code, there's no evidence of the "selected".

 

Thanks again,

 

~Wayne

Does your form use the post or get methods? Also, you still didn't change a part.

 

<select name="link">
<option value="<?php echo $page_name; ?>&limit=25"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=25") ? ' selected="selected"' : ''; ?>>25</option>
<option value="<?php echo $page_name; ?>&limit=50"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=50") ? ' selected="selected"' : ''; ?>>50</option>
</select>

 

Where is $page_name defined? Why do you even need it there?

$page_name = $_SERVER["REQUEST_URI"];

 

Post, I think.

 

It grabs the current URL, with all the current queries, and then the form is actually a link that takes that URL and modifies "limit", changing the number of records displayed on a page.  It's worked in other instances exactly the way I want it to.

 

Sorry, I was missing the semicolons... I've corrected that, still no dice:

 

<select name="link">
<option value="<?php echo $page_name; ?>&limit=25"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=25") ? ' selected="selected"' : ''; ?>>25</option>
<option value="<?php echo $page_name; ?>&limit=50"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=50") ? ' selected="selected"' : ''; ?>>50</option>
</select>

 

Thanks,

 

~Wayne

<form name="form" method="post">
<select name="link">
<option value="<? echo $page_name; ?>&limit=25"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=25") ? ' selected="selected"' : ''; ?>>25</option>
<option value="<? echo $page_name; ?>&limit=50"<?php echo (isset($_POST['link']) && $_POST['link'] == "$page_name&limit=50") ? ' selected="selected"' : ''; ?>>50</option>
</select>
 <input type="button" value="Go" onClick="openURL()">
</form>

 

The link is fired by this JS:

<script type="text/javascript"><!--
function openURL()
{
      selInd = document.form1.link.selectedIndex;

      goURL = document.form1.link.options[selInd].value;

      top.location.href = goURL;
}

//-->
</script>

 

Thank you.

 

~Wayne

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.