Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:18:46+00:00 2026-05-27T21:18:46+00:00

I’m wondering if the following may be possible using something like jQuery. I’ve looked

  • 0

I’m wondering if the following may be possible using something like jQuery. I’ve looked all over but haven’t found a solution.

I am using MVC 3/razor for my project. I have jQuery 1.5.1.

We want a dropdown (select) box that will show a few options:
– Monthly
– Annually
– Weekly
– Date

If the user selects ‘Date’ I’d like to show a calendar box and then record the selected date as the value in the select box. If they click the select box again they can change the values as per the original select values.

In my project there are several of these boxes on the same page. Perhaps I could tie them to a click action via a class value?

The closest request I’ve found to this point was here: jQuery ui.datepicker on 'select' element
… but I’ve not been able to get that working for my project quite yet.

Any help is appreciated.

Update
The added elements which I need to tie to are inserted to the page dynamically. Perhaps this is where my challenge is coming from.

Update

Here is some code I’m using/messing with at this moment:

First – my code is added dynamically from a template. The field that I’m looking to tie to is below and may exist multiple times across the page:

<td><select id="f${FormCount}_PeriodWorked[]" name="PeriodWorked" class="periodworked">
                <option value="month">Month</option>
                <option value="annual">Annual</option>
                <option value="date" class="datepick">Date</option>
                </select>
</td>

On the main page, where the form is dynamically added to, I have the following which attempts to add the datepicker to the option ‘date’.

$(".periodworked").live("change", function () {
    if ($(this).val() == "date") {
        alert("In... now how to throw date picker....");
    }
})

Lastly – tying this to respective fields… is there a way to use $(this) for handling that or do I have to come up with some other way to find the specific select I’ve chosen?

UPDATE

Thanks for the help – I managed to get it working. I understand my circumstance is very specific, but here’s the code if it helps anyone else…

First – via CSS I use colors to hide the form fields (same bg color as table – emulating an MS Excel look). The font color for the input field showing the datepicker is using this same color to prevent any text being seen (though if seen it’s only a flicker before the field is hidden).

In my template I modified the cell as below:

<td><select id="f${FormCount}_PeriodWorked[]" name="PeriodWorked" class="periodworked add-date">
                <option value="month">Month</option>
                <option value="annual">Annual</option>
                <option value="date" class="datepick">Date</option>
                </select>
                <input name="tempDatePicker" type="text" size="1" class="datepicker for-option" style="display:none; color: #EFEFEF;" /></td>

In my main page I had to do a few ‘funny’ things. Here’s the code:

$("select.add-date").live("change", function () {
    if ($(this).val() == "date") {
        //alert("In... now how to throw date picker....");         
        $(this).parents('td').find('input.datepicker').show();
        $(this).parents('td').find('input.datepicker').datepicker({
            onSelect: function (dateText, inst) {
                var opt = $('<option />').attr('value', dateText).attr('selected', 'selected').text(dateText);
                var select = $(this).parents('td').find('select.add-date');
                // NOTE: ommitted code to check if the date is already in the select     
                $(select).append(opt);
            }
        }).focus();
    } else {
        $(this).parents('td').find('input.datepicker').hide();
    }
});

$('input.datepicker.for-option').live('blur', function (dateText, inst) {     
    $(this).hide(); 
});

You will notice I’ve added the datepicker to the input within the live/change function. For some reason this is the only way it would work (opposed to placing the datepicker outside of the live). This also allowed me to use the onSelect method which pulled the chosen value from the calendar properly where as the blur wasn’t retrieving the value and returned blank results, for whatever reason.

My blur method simply hides the input field containing the calendar.

This all works fine – but in my case I am adding many fields dynamically by copying the first row of a table and appending it to the existing table. Everything worked fine unless you use the datepicker within that row. At that point a class and id is assigned to the input object of the datepicker, which is then copied, and screws everything up. To fix this I added a method to my insertRow function to basically drop the insert and re-write it. God I hope that makes sense… code:

    function addLines(formNum, lines) {
        for (var l = 0; l < lines; l++) {
            var table = document.getElementById("formTable_" + formNum);
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);

            var colCount = table.rows[0].cells.length;

            for (var i = 0; i < colCount; i++) {
                var newcell = row.insertCell(i);

                if (table.rows[1].cells[i].innerHTML.search('name="PeriodWorked"') != -1) {
                    newcell.innerHTML = table.rows[1].cells[i].innerHTML.substr(0, table.rows[1].cells[i].innerHTML.search("<input"));
                    newcell.innerHTML = newcell.innerHTML +
                        '<input name="tempDatePicker" type="text" size="1" class="datepicker for-option" style="display:none; color: #EFEFEF;" />';
                } else {
                    newcell.innerHTML = (table.rows[1].cells[i].innerHTML);//.replace(" hasDatepicker", "");
                }

                //newcell.childNodes[0].id = "f" + formNum + "_" + newcell.childNodes + (1 + parseInt(newcell.childNodes[0].id.substr(newcell.childNodes[0].id.lastIndexOf("_") + 1));

                switch (newcell.childNodes[0].type) {
                    case "text":
                        newcell.childNodes[0].value = "";
                        break;
                    case "checkbox":
                        newcell.childNodes[0].checked = false;
                        break;
                    case "select-one":
                        newcell.childNodes[0].selectedIndex = 0;
                        //resetDatePicker();
                        break;
//                  default:
//                      newcell.innerHTML = "";
//                      break;
                }
            }
        }
    }

Again – I appreciate the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:18:46+00:00Added an answer on May 27, 2026 at 9:18 pm

    To answer the jquery part of your question, you could do this:

    <td>
        <div>
            <select id="f${FormCount}_PeriodWorked[]" name="PeriodWorked" 
                class="periodworked add-date">
                <option value="month">Month</option>
                <option value="annual">Annual</option>
                <option value="date" class="datepick">Date</option>
            </select>
        </div>
        <div>
            <input type="text" class="datepicker for-option" style="display:none;" />
        </div>
    </td>
    

    …and then…

    $('input.datepicker').datepicker();
    $("select.add-date").live("change", function () {
        if ($(this).val() == "date") {
            //alert("In... now how to throw date picker....");
            $(this).parents('td').find('input.datepicker').show();
        }
        else {
            $(this).parents('td').find('input.datepicker').hide();
        }
    });
    $('input.datepicker.for-option').live('blur', function() {
        var select = $(this).parents('td').find('select.add-date');
        // NOTE: ommitted code to check if the date is already in the select
        $('<option value="' + $(this).val() + '" selected="selected">' + 
            $(this).val() + '</option>').appendTo(select);
        $(this).hide();
    });
    

    This should work with text box blur, but you might be able to use the datepicker’s onSelect event to add the option to the select. I have used blur because I know it works with live.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.