简体   繁体   中英

how to disable clicking of calendar after first click?[edited for solution]

i am using an DHTML calendar in my application. on clicking a date ,there is a form submit action.

i want to disable the calendar after first click ,so that user can not click the other date before the form submit.

my code is

<SCRIPT type="text/javascript">

function dateChanged(calendar) 
{
    // Beware that this function is called even if the end-user only
    // changed the month/year. In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
    // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
    var y = calendar.date.getFullYear();
    var m = calendar.date.getMonth() + 1; // integer, 0..11
    var d = calendar.date.getDate(); // integer, 1..31
    var NewDate = y + "-" + m + "-" + d;
    document.getElementById("<?=$mydata[FILTER]?>").value = NewDate;
    submitForm();
}




    var tempDate = new Date(<?=$CalDate?>);
    Calendar.setup({
            flat        : "<?=$mydata[FILTER]?>_show_date",     // ID of the parent element
            flatCallback:dateChanged,                                           // our callback function
            weekNumbers:false,                                              // Don't display week numbers
            date        : tempDate      
                    // Set calendar to start at selected date
        });

    document.getElementById("<?=$mydata[FILTER]?>").value = '<?=$mydata[FILTER]?>';

i made a solution for this i disabled div and all the children of div using the code

**var nodes = document.getElementById("13-1_show_date").getElementsByTagName('*');
for(var i = 0; i < nodes.length; i++)
{                                               
nodes[i].disabled = true;
}     
submitForm();**

this code will disable the div and its childrens after first click.

This problem is a classical problem, and there are many ways:

  1. Use a temporary variable called isClciked and set it to true in the first click, and in subsequent clicks, check it, and if it's true, then simply return; .
  2. On the first execution of your click handler, disable the entire calender (this in itself has many ways)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM