0

I'm simply trying to set a value for an input but it doesn't work. Here is my jquery function :

function display_form() {
    try {
        $('#start_date').val('2012/08/21');
    } catch (e) {
        alert('error');
    }

   // window.alert($('[name=start_date]').val()); (shows "undefined")
   $('#add-event').show();
}

This is how display_form is called:

$(document).ready(function() {
        $('#calendar').fullCalendar({ 
            dayClick: function(date, allDay, jsEvent, view)
            {     
                date_format = $.fullCalendar.formatDate(date,"yyyy-MM-dd HH:mm:ss");
                    display_form();
                    return false;

                },
            events: 'https://www.google.com/calendar/feeds/myLogin%40gmail.com/public/basic'
        });
    });

This shows "undefined". Here is my form :

<input id="start_date" name="start_date" type="text" size="6" />

Should I put somewhere the id of the form that I want to use? I just followed what is said in the documentation of jquery but it doesn't seem to work. Could anyone help me ?

4
  • 1
    have you call display_form() somewhere? Commented Aug 31, 2012 at 9:38
  • @user1499229 check my solution below. Your code should work fine Commented Aug 31, 2012 at 9:44
  • are you sure the calendar plugin does not add another input or changes the name /class of yours? Commented Aug 31, 2012 at 11:10
  • Could you tell me please how can I check this? Commented Aug 31, 2012 at 11:21

2 Answers 2

1

This will help

window.alert( $('input[name=start_date]').val() ); 



function display_form() 
    {   try {
        $('#start_date').val('2012/08/21');
        }catch (e){
                     alert('error');
                 }

       window.alert( $('[name=start_date]').val() ); 
       }

$(document).ready(function() {
$('#press').click(function() {
  display_form();
  });
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Codesesn but I don't understand how the call of display_form would be done if I put $('#press').click. Actually, it is display form which would display the form after setting the start date value
0

HTML

<input id="start_date" name="start_date" type="text" size="6" />
<button id="press">Press</button>

JavaScript

function display_form() {
    try {
        $('#start_date').val('2012/08/21');
    } catch (e) {
        alert('error');
    }

    window.alert( $('[name=start_date]').val() ); 
}

$('#press').click(function() {
    display_form();
 });

jsFiddle

4 Comments

it still not working for me. Actually display_form is called from another function.And I checked the call with putting an alert in the beginning of the function !
Could you provide a little more code so that I understand what exactly is happening.
can you do console.log('something') inside $('#calendar').fullCalendar({ }) and check if it logs something in console.
console.log doesn't show anything but all what I put inside dayClick is executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.