if a or b selected from select menu i want to submit values else other is selected from select menu i want to redirect to other website please help me urgent.

** my form code is **

 <table> 
 <tr>

    <td><label>
      <select name="community" id="select7" >
        <option value="a">a</option>
        <option value="b">b</option>
        <option value="other">other</option>
      </select>
    </label></td>
  </tr>
  <tr>
    <td><input type="submit" name="button" id="button" value="search" tabindex="50" /></td>
  </tr>
</table>

Thanks you,

Dani AI

Generated

was right to point out the missing form and incorrect label use, and ’s inline onchange is a quick fix (and explains why ’s follow-up reported “working perfectly!”). For a more robust, accessible solution that’s easier to maintain, handle the redirect at form-submit time with unobtrusive JavaScript and keep a server-side fallback so the flow still works when JS is disabled.

Use a submit listener that checks the select value and either allows normal submission (for a/b) or performs a client redirect for other. This keeps keyboard/assistive-device behavior predictable and avoids surprising users with immediate navigation on selection:

<script>
document.addEventListener('DOMContentLoaded', function () {
  var form = document.getElementById('searchForm');
  var selectEl = document.getElementById('communitySelect');
  var redirectMap = { other: 'https://example.com' }; // map select values to URLs

  form.addEventListener('submit', function (evt) {
    var v = selectEl.value;
    if (redirectMap[v]) {
      evt.preventDefault();
      window.location.href = redirectMap[v]; // same-tab redirect
      // to open in new tab safely:
      // var win = window.open(redirectMap[v], '_blank');
      // if (win) win.opener = null;
    }
    // otherwise let the browser submit the form normally
  });
});
</script>

Notes and quick checks:

  • Use <label for="communitySelect"> (don’t wrap the select incorrectly).
  • Provide a server-side check for other so non-JS clients are redirected or handled appropriately.
  • Avoid automatic onchange redirects unless the UX clearly expects immediate navigation.
  • If opening an external site in a new tab, prefer rel="noopener noreferrer" or set win.opener = null to prevent tab-napping.

Troubleshooting: verify IDs match, ensure the script runs after the DOM, watch the console for errors, and confirm the submit button is type="submit".

Recommended Answers

All 3 Replies

I think this is a JavaScript question, also, the label tags are wrong and nothing will work if it's not within <form></form> tags

Change line 5 to:

<select name="community" id="select7" onchange="javascript:if(this.value=='other')window.location.href='REDIRECT/PATH/HERE';">

If you need this to be more scalable, you can make it a JS function instead.

EDIT: Good catch, TonyG. Those <label> tags don't belong there, and while the onchange will handle redirects, submitting won't work without <form> tags.

working perfectly!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.