-3

I have a drop down menu and it will forward to the link when user clicks it Please click here to view I dont want any button just when user select category it will forward it to them. I want to remove the button when user want they click the menu and when select it will forward to the domain. Please guide me. Thanks...

The button code is

<FORM name="mapform" method="POST">
<SELECT name="jump" size="1">
<OPTION value="" SELECTED>Select the Category</option>
<OPTION value="http://www.mydomain.com/posting.php?mode=post&f=1">Ask a Question</option>
<OPTION value="http://www.mydomain.com/posting.php?mode=post&f=4">Vehicle for Sale</option>
<OPTION value="http://www.mydomain.com/posting.php?mode=post&f=8">Housing for Rent</option>
</SELECT>
<INPUT type=button onClick= "location = '' + document.mapform.jump.options[ document.mapform.jump.selectedIndex ].value;" value="Place an Ad!">
</FORM>

Additional Help :) if possible can you tell me how to make this button look good like nice themes...

MrCode
  • 63,975
  • 10
  • 90
  • 112
user1820652
  • 178
  • 2
  • 3
  • 9

3 Answers3

1

Move the onclick code to the dropdown's onchange event:

<SELECT name="jump" size="1" onchange="window.location = this.value;">

Although, I suggest creating a function instead of throwing all of the code in the inline event because you will need to check if the Select the Category option is selected and therefore don't redirect.

<script>
function changeCategory(value)
{
    if(value != "")
    {
        window.location = value;
    }
}
</script>

<SELECT name="jump" size="1" onchange="changeCategory(this.value)">
MrCode
  • 63,975
  • 10
  • 90
  • 112
1

Try this
HTML

<SELECT name="jump" id="jump" size="1">
<OPTION value="" SELECTED>Select the Category</option>
<OPTION value="http://www.mydomain.com/posting.php?mode=post&f=1">Ask a Question</option>
<OPTION value="http://www.mydomain.com/posting.php?mode=post&f=4">Vehicle for Sale</option>
<OPTION value="http://www.mydomain.com/posting.php?mode=post&f=8">Housing for Rent</option>
</SELECT>

JQUERY SCRIPT

<script>
    $(function(){

      $('#jump').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>
guri
  • 662
  • 2
  • 8
  • 26
1

You have to trigger it while onChange of that drop-down.

In onChange of that drop-down, you can call a Javascript function and in that function you can redirect it.

OR

You can create an id for that <select> and create onchange event:

<SELECT name="jump" size="1" id="category">
<script type="text/javascript">
   $(document).ready(function() {
      $("#category").onchange(function() {
        // do redirect here  ....................
      });
   });
</script>
Jon Adams
  • 24,464
  • 18
  • 82
  • 120
Vinoth Babu
  • 6,724
  • 10
  • 36
  • 55