Clicking the button to make selection from drop down menu

I’m trying to make these section go to specific pages but not sure where to go from here. Can someone help me please with sample url pages. Here is my code:

<div style="background-color:#cde4f1;padding:10px 5px 30px 5px;width:70%;">
<p><strong>Ut varius lorem mi, non tristique felis hendrerit id.</strong></p>
<select>
<option>--Choose--</option>
<option>3 parts Medications </option>
<option>4 parts Medications </option>
<option>Medication page</option>
</select>
<button type="button">Go</button>
</div>

Try with the following code:

<div style="background-color:#cde4f1;padding:10px 5px 30px 5px;width:70%;">
<p><strong>Ut varius lorem mi, non tristique felis hendrerit id.</strong></p>
<select name='form' onchange="location = this.value;">
<option>--Choose--</option>
<option value="3 parts_Medications.php">3 parts Medications </option>
<option value="4 parts_Medication.php">4 parts Medications </option>
<option value="Medication_page.php">Medication page</option>
</select>
<button type="button">Go</button>
</div>

Maybe you will not must to use the button element but try this.

1 Like

Good solution by @liontas76
Using that you will not need a submit button. The user goes directly to the url specified in the value part on selecting that option.
If you need to pass some value along with the url use URL params at the end of your url.

thank you so much for your help. I really enjoy the support I get from this community. What would it be like if I were to incorporate the button?

JS shouldn’t be relied upon to navigate to pages so make sure that the form is backed up with a server side script to take care of that as documented here. :slight_smile:

1 Like

@PaulOB as per the requirement of the OP it looks like a simple requirement of conditional navigation. If it was a part of a form obviously one would need to wait till other fields are filled and the button is pressed.

Can you explain why you are using form input elements for what appears to be navigation?
I presume there is some reason, but I don’t get it.

1 Like

I don’t think that has anything to do with what I was saying:)

I was simply saying JS shouldn’t be relied for navigation and if JS is disabled the site should still be navigable which for a select can be achieved by submitting the form and then re-directing the page as required.

If js is not available then show the ‘go’ (submit) button and if js is available hide the button and let the onchange do the work. It’s a win win situation :slight_smile:

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.