user435245
user435245

Reputation: 859

Two sequential java script date picker functions

I'm using a java script calendar date picker, my input fields and related java scripts are like below:

<input type="text" class="text date" maxlength="12"  name="customerServiceAccountForm:fromDateInput" id="customerServiceAccountForm:fromDateInput">

<script type="text/javascript">&lt;!--
    document.body.onload = function(){
        Calendar.setup({
           inputField     :    'customerServiceAccountForm:fromDateInput',
           ifFormat     :    '%Y/%m/%d',
           showsTime     :    false,
           button     :    'fromCalendar',
           singleClick     :    true,
           step     :    1,
           dateType     :    'jalali',
           range     :    [1300,1600]
     });
}
//--&gt;</script>

<input type="text" class="text date" maxlength="12" name="customerServiceAccountForm:toDateInput" id="customerServiceAccountForm:toDateInput">

<script type="text/javascript">&lt;!--
    document.body.onload = function(){
        Calendar.setup({
            inputField     :    'customerServiceAccountForm:toDateInput',
            ifFormat     :    '%Y/%m/%d',
            showsTime     :    false,
            button     :    'toCalendar',
            singleClick     :    true,
            step     :    1,
            dateType     :    'jalali',
            range     :    [1300,1600]
       });
}
//--&gt;</script>

but when the page loads only the last date picker show up, what is the problem and how can I solve this problem. by the way this problem occurred after I surrounded the java script tags by a document.body.onload = function() wrapper. What is going wrong with the date picker and how can I solve this thing?

Upvotes: 0

Views: 283

Answers (1)

BigBadOwl
BigBadOwl

Reputation: 678

You can only have one body onload function. Instead create a single body onload function and add both calendars to it. Example...

function load(){
  loadCalendar1();
  loadCalendar2();
}

document.body.onload = load();

Also, I would move the javascript to a single script tag within the head tag of your html page, before the body tag.

Upvotes: 1

Related Questions