-2

I have this php code to generate a select form. What I'm looking for is create a "X" button at right side for resetting the form to default value [0] index. Here is a picture of what I want to accomplish. How can I do that? Thanks This is where the X should be located

echo '<li><div class="styled-select">' . tep_draw_form('sort',` 
    htmlentities($_SERVER['PHP_SELF']), 'get') . '';
    $sort_list = array('0' => 'Sort By',
                       '1' => 'Product Name',
                       '2' => 'Price: Low to High',
                       '3' => 'Price: High to Low',

    echo tep_draw_hidden_field('page', $page);
    foreach($sort_list as $id=>$text) {
    $sort_range[] = array('id' => $id, 'text' => $text);
                                     }
    echo tep_draw_pull_down_menu('sort', $sort_range, (isset($HTTP_GET_VARS['sort']) ?
    $HTTP_GET_VARS['sort'] : ''), 'onchange="this.form.submit()"');
    echo '</form></div></li>';
JuanPer
  • 53
  • 1
  • 1
  • 5

1 Answers1

0

Try changing your last echo statement to the following. You may need to do some styling with CSS to get X looking exactly the way you want and get it positioned right if necessary (.changeme class):

echo ' <a href="#" onclick="document.sort.sort.selectedIndex = 0" class="changeme">X</a></form></div></li>'
artybug
  • 30
  • 2
  • I can position the X where I want using the position property, however, there is no change on the form after clicking X. Ex. I select the index 2, the address bar add this to the end: ?sort=2 and when I mouseover the X I this is the link: ?sort=2#. If I click X, the end of the address bar change to ?sort=2# but nothing happens. I'm proficient on html and css but no in php and javascript. I'm trying to learn and I appreciate any help. Great for those who never need to ask questions. Thank you. – JuanPer Mar 27 '16 at 15:50
  • can you copy and paste the actual html from view source starting with the form tag and ending with the closing form tag? – artybug Mar 27 '16 at 17:05
  • I have made a change. Please use onclick="document.sort.sort.selectedIndex = 0" for the onclick attribute. If that doesn't work, please paste the entire form code block from view source. – artybug Mar 27 '16 at 17:12
  • Ok, with the new onclick I got the value name changed on the form but nothing happen, the page doesn't refresh. This is the source code:
  • – JuanPer Mar 27 '16 at 17:39
  • I thought you just wanted to reset it to the first element. Do you also need to have the form submit automatically? if so, change it as follows. onclick="document.sort.sort.selectedIndex = 0; document.sort.submit()" – artybug Mar 27 '16 at 17:55
  • Artur that was perfect. Thank you for your time. – JuanPer Mar 27 '16 at 18:10