I have a problem - I need some help.

I am having trouble with some coding. I have created a drop down list with the months of the year. Next to this I have created a button.

What I want to do is when the user selects a month from the drop down menu, and then selects "Click Me", it takes the user to that particular month.

Can anyone help?

Thanks GK

Recommended Answers

All 10 Replies

GK2011, please do not hijack old post. This post is 2 years old! Please create a new thread if you are going to ask a question. You may add a link back to old posts if you want to in order to relate your subject to the post.

Anyway, do you mean you want a page to be redirected after the button "Click Me," is clicked? You could simply use window.location.href='path_to_location' in your function and use if-else or switch to make the decision for you. Remember, you need a fully qualified URL. This means it includes the domain name as well (i.e. en.wikipedia.org/wiki/Fully_qualified_domain_name).

// in Java Script
function moveToMonth(selectID) {
  var el = document.getElementById(selectID)
  if (el) {  // ensure the element exists
    var idx = el.selectedIndex
    switch (idx) {
      case 1:  // January
        window.location.href = "fully_qualified_path_to_page"
        break
      case 2:  // February
        window.location.href = "fully_qualified_path_to_page"
        break
      case 3:  // March
        window.location.href = "fully_qualified_path_to_page"
        break
      ...
    }
  }
}


// in HTML
<select name="selectMonth" id="selectMonth">
 <option value=0>Select Month</option>
 <option value=1>January</option>
 <option value=2>February</option>
 ...
</select>
<input type="button" value="Click Me" onclick="moveToMonth('selectMonth')">

Is you asking for that when you select the month from the drop down and then click the button it take you the particular month mean (correct month if it is 11th).Is this what you asking if so let me known

What I mean is, when a user selects a month from the drop down menu and then selects "Click Here" a new window opens with that month. I am not going into specific dates - just months. I hope this helps.

Thank you

GK2011

sorry to make it clear it again so that i can help you to solve your query.so you want if you select month from dropdown list and hit the button so want alert box with month specfied there or you want to echo that month just in a new window after hitting button

When you have selected the month and hit the button, a new window should open with that month you selected.

GK2011

Please define "a window"? You mean a whole new page or just a message? Try this in your select tag...

<select onchange="javascript:alert('Selected '+this.value)">
  <option value="January">January</option>
  <option value="February">February</option>
  <option value="March">March</option>
  ...
</select>

If it is what you want, it is not really a window but a message pop up.

Well your question was bit tricky.i have coded your query look if it help you and if further you have any questions regarding that code i will be there to answer.below are the file

Regards

A "window" is defined as a whole new page.

GK2011

OK, do you have HTML files for each of the selection in the same folder as your main HTML page? You need them in order to open new window because you need to give URL to it. The command you need is window.open() and its syntax is as follows:

window.open('URL_to_open', 'window_name', 'attribute1, attribute2, ...')

A sample short script here is to show you how to do it. However, it expects that all files exist in the same location as the main HTML and the file name must match each month. You could still modify my first post script to work as a function.

<select onchange="javascript:window.open(this.value+'.html', this.value, 'width=500,height=300')">
  <option value="January">January</option>  <!-- expect January.html to exist -->
  <option value="February">January</option>  <!-- expect February.html to exist -->
  <option value="March">January</option>  <!-- expect March.html to exist -->
  ...
</select>

Thank you

GK2011

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.