Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Fill field with day of week field upon user selected date.

    Hi folks.

    Looking to see if anyone could tell me where I'm going wrong with this script...

    I'm trying to have a field automatically filled with the day of the week ("Monday", "Tuesday", "Wednesday" and so on), upon the user selecting a date from the datepicker jQuery. If this isn't clear, I'll clarify further down the page.

    Here is the script:
    Code:
    <script type="text/javascript">
    jQuery(document).ready(function($){
    $('input[name="item_meta[428]"]').change(function(){
    var d = $('input[name="item_meta[428]"]').val();
    var n = new Date(d).getDay();
    if(n == 0)
    val v = 'Sunday';
    else if(n == 1)
    val v = 'Monday';
    else if(n == 2)
    val v = 'Tuesday';
    else if(n == 3)
    val v = 'Wednesday';
    else if(n == 4)
    val v = 'Thursday';
    else if(n == 5)
    val v = 'Friday';
    else if(n == 6)
    val v = 'Saturday';
    $('input[name="item_meta[429]"]').val(v).change(); 
    });
    });
    </script>
    I'm basically trying to say, if the user selected today (15/05/2012) in the field 428 it would fill the field 429 with "Tuesday".

    Again, if the user selected 18/05/2012 in the field 428 then it would automatically fill field 429 with "Friday".

    It's being done to work in conjunction with a wordpress plugin called Formidable Pro hence the item_meta[428] etc.

    Any assistance would be greatly appreciated.

    Sam.
    Last edited by suscott; 05-15-2012 at 10:17 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Well, I don't use jQuery, but I don't know why the following won't work:
    Code:
    jQuery(document).ready(function($){
           $('input[name="item_meta[428]"]').change(function(){
           var d = $('input[name="item_meta[428]"]').value;
           var wdays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
            $('input[name="item_meta[429]"]').value = wdays[(new Date(d)).getDay()];
        });
    })
    Instead of using jQuery's val() function, why not use the .value property for the <form> field??? Surely that's what val( ) is doing, under the covers.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •