0

I am facing this issue here.After i click alert in if statement the page should not reload.I have tried everything here

  1. return false;
  2. event.preventDefault(); 3.window.stop();//This is working but for other conditions where page should reload it is not getting loaded. 4.return;

So as you can see in if statement when sel.options[sel.selectedIndex].text!="Meeting Room Name the alert is showed after i click ok the page should not reload.I have tried each and every solution and referred many posts.

  $("input[id$='diidIOSaveItem']").click(function(ev) 
{
    var startDate = $("input[id$='DateTimeField_DateTimeFieldDate']")[0].value;
    var EndDate = $("input[id$='DateTimeField_DateTimeFieldDate']")[1].value;
    var startH = $("select[id$='DateTimeFieldDateHours']")[0].value;
    var endH = $("select[id$='DateTimeFieldDateHours']")[1].value;
    var startM = $("select[id$='DateTimeFieldDateMinutes']")[0].value;
    var endM = $("select[id$='DateTimeFieldDateMinutes']")[1].value;
    var meetingTitle = $("input[id$='TextField']").val();

    if(meetingTitle == "" || meetingTitle == "undefined")
    { 
    alert("You have not entered a Meeting Title.");
    $("input[id$='TextField']").focus();
    }


    if(startDate != EndDate)
    {
    alert("Each Meeting must start and finish on the same day.");
    $("input[id$='DateTimeField_DateTimeFieldDate']").focus();
    }
    if(startH == endH && startM == endM) 
    {
    alert("End Hour/Minutes and Start Hour/Minutes can not be same.");
    $("select[id$='DateTimeFieldDateHours']").focus();
    }

    if(startH > endH ) 
    {
    alert("End Hour must be greator than or equal to Start Hour.");
    $("select[id$='DateTimeFieldDateHours']").focus();
    }
     if(sel.options[sel.selectedIndex].text =="Meeting Room Name")   //if no meeeting room or more then one meeting room is selected.
            {
                alert("Please select One Meeting Room");

                //$("input[id$='DateTimeField_DateTimeFieldDate']").focus();    
                // ev.preventDefault();         
                return false;   
            }

    if(sel.options[sel.selectedIndex].text!="Meeting Room Name")
    {           
            //if without any room selection clicking on save.
            if(selectedValue.length == 1)
            {
                if(selectedValue.options[selectedValue.selectedIndex] != "undefined")
                {
                    selectedValueres= selectedValue.options[selectedValue.selectedIndex].text;
                    //sel.options[sel.selectedIndex].text= selectedValueres ;
                    if((selectedValueres != "")&&(selectedValue.length == 1))
                    {console.log("selectedValueres  "+ selectedValueres);
                        if (!PreSaveItem())return false;
                        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl40$g_2543e208_7ccd_45b5_9c3c_703dd452cee7$savebutton2$ctl00$diidIOSaveItem", "", true, "", "", false, true));
                    }
                    else    //if no meeeting room or more then one meeting room is selected.
                    {
                        //alert("Please refresh page and click on new booking your booking is conflict with other user.");      
                    GipAddSelectedItemsModified(ctl00_ctl40_g_2543e208_7ccd_45b5_9c3c_703dd452cee7_ff41_ctl00_ctl00_MultiLookupPicker_m); 
                        selectedValueres= $("tr.tobehide select[id$='SelectResult']").find(":selected").text();

                $("<option value='new value' selected='selected'>"+selectedValueres+"</option>").prependTo($("tr.tobehide select[id$='SelectCandidate']")); 

                    }
                    //sel.options[sel.selectedIndex].text= selectedValueres ;
                }
                else    //if no meeeting room or more then one meeting room is selected.
                {
                    alert("Please select One Meeting Room");        
                    return;

                }
             }

            }

        return false;

});
  • Exactly what type of element is `diidIOSaveItem` ? I suspect it's `type='submit'` eg `` if so, change it to `type='button'` eg ``. Or change your handler to `$("input[id$='diidIOSaveItem']").submit(` (instead of .click). – freedomn-m Nov 06 '17 at 15:51
  • See http://idownvotedbecau.se/toomuchcode/ and [mcve]. You should be able to reduce the code to one or two lines to demonstrate the problem. – freedomn-m Nov 06 '17 at 15:53
  • It may also depend on what your `PreSaveItem()` does - if it's ajax then see http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call/14220323 – freedomn-m Nov 06 '17 at 15:54

0 Answers0