Reputation: 1
Hy there
I have some selecboxes on my site like this one:
<div class="registrationdate">
<select class="filter registrationdate" name="rdat" id="regdate">
<option value="">---</option>
<option value="2012">at 2012</option>
<option value="2011">at 2011</option>
<option value="2010">at 2010</option>
</select>
</div>
now i got a problem after submit the form... if "at 2011" is selected after submit i get just "2011", the value, but i want the text. after refresh the select boxes change the text to "at 2011"
in source i can see the problem, but i don't know how to solve it. after submit the form and i land on the same page the source of the selectbox above is altered like this:
<div class="registrationdate">
<select class="filter registrationdate" name="rdat" id="regdate">
<option value="2012">2012</option>
<option value="">---</option>
<option value="2012">at 2012</option>
<option value="2011">at 2011</option>
<option value="2010">at 2010</option>
</select>
</div>
so can here some help me? i hope i expressed me understandable. thanx for help!
EDIT
OK, i think i have found the Problem in the code of my coworker... but i encounter another problem, the same what he wanted to solve. This is the actual code:
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' name='filterform' method='get' class="filterform">
<div class='registrationdate'>
<strong><?php echo $GLOBALS['Lng']['filter_Erstzulassung']; ?>:</strong>
<select id="regdate" name="rdat" class="filter registrationdate">
<?php if (isset($_GET['rdat'])&&$_GET['rdat']!='') echo '<option value="'.$_GET['rdat'].'">'.$_GET['rdat'].'</option>'; ?>
<option value="">---</option>
<?php for ($i = date(Y); $i >= (date(Y)-7); $i-- ) {
echo '<option value="'.$i.'">ab '.$i.'</option>';
}?>
</select>
</div>
<input type="submit" value="<?php echo $GLOBALS['Lng']['apply']; ?>" name="submit" id="submit" class="field">
</form>
The Problem is that he want the entered option visible again after submit the form. In normal case if you send a form u got the default values. he tried to overwrite this with the php part "isset then echo". AFAIK PHP you can't get the Text part of an select field, or? What could he else to solve this?
Upvotes: 0
Views: 270
Reputation: 744
As far as I understood, you want to keep value
attribute, but get the text inside option
tag.
$("#regdate option[value='2011']").text()
will return "at 2011"
Upvotes: 0
Reputation: 3644
If you wish to get "at 2011" you should set value of the option to
<option value="at 2011">at 2011</option>
Upvotes: 1