I am working on a C# Razor site and I am POSTing from a boostrap modal which then returns a new view and model. To reload the entire page with the response, I am using the following line within this code block.  $("html").html(response);   function addDevice(e) {         e.preventDefault();         var ID = $("#txtNewDeviceID").val();         var Name = $("#txtNewDeviceName").val();          $.post('@Url.Action("AddDevice", "Devices")', { 'DeviceID': ID, 'DeviceName': Name }, function (response) {             $('#newDeviceModal').modal('hide');             $("html").html(response);             AttachBindings();         });     }   Here is the code behind AttachBindings():  function AttachBindings() {         $(document).on('click', 'table tr', {}, tableClick);         $(document).on('keyup', '#search', {}, search);         $(document).on('click', '#btnAdd', {}, function (e) {             addDevice(e);         });         $(document).on('click', '#btnRemove', {}, function (e) {             removeDevice(e);         });         $(document).on('click', '#btnUpdate', {}, function (e) {             updateDevice(e);         });     }   Unfortunately AttachBindings() is never hit and I can't seem to find a way to reattach these events. The only event that seems to work is keyup which is attached to #search.  Any ideas on how to fix this?
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
24342
I have a system where I send an Ajax command, which returns a script block with a function in it. After this data is correctly inserted in the DIV, I want to be able to call this function to perform the required actions.  Is this possible?
40753
Recently I have started playing with jQuery, and have been following a couple of tutorials. Now I feel slightly competent with using it (it's pretty easy), and I thought it would be cool if I were able to make a 'console' on my webpage (as in, you press the ` key like you do in  games, etc.), and then have it Ajax itself back to the server in-order to do stuff.  I originally thought the best way would be to just get the text inside the textarea, and then split it, or should I use the keyup event, convert the keycode returned to an ASCII character, append the character to a string and send the string to the server (then empty the string).  I couldn't find any information on getting text from a textarea, all I got was keyup information. Also, how can I convert the keycode returned to an ASCII character?
92276
I have a form that is dynamically generated, and has dynamically generated id's (and potentially classes). The forms are the same but they have the related id tacked on to the end.  How can I select each set of inputs and apply code to each one?  I was experimenting with $('input[id^=@id_airline_for_]') but could not get it to fly. I suspect I am missing some fundamental jQuery knowledge that is holding me back since I am sure this is a common problem with dynamic forms.   &lt;form method='POST'&gt;     &lt;label for="id_airline_for_8"&gt;Airline&lt;/label&gt;:     &lt;input id="id_airline_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="airline_for_8"/&gt;     &lt;label for="id_flight_number_for_8"&gt;Flight Number&lt;/label&gt;:     &lt;input id="id_flight_number_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="flight_number_for_8"/&gt;      &lt;label for="id_airline_for_17"&gt;Airline&lt;/label&gt;:     &lt;input id="id_airline_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="airline_for_17"/&gt;     &lt;label for="id_flight_number_for_17"&gt;Flight Number&lt;/label&gt;:     &lt;input id="id_flight_number_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="flight_number_for_17"/&gt;      -- snip --  &lt;/form&gt;   EDIT: I should update that i want to be able to perform some action when the input is clicked but only for classes with a matching id at the end.  To make it easy, lets say I want all inputs with a matching id at the end of the #id to disappear when one is clicked (just for arguments sake).
24463
Question: How to pop-up alert to a user when he/she navigate away from page without saving the Records in custom visual force page?  Details:  I have a custom visual force page i.e. "My Members" that have the following code:  &lt;apex:page Controller="MyMember" &gt; &lt;script&gt;  function mytest() {  if (!confirm('Are you sure to naviagte without saving Records?')) {   }  else {return true;} }  window.onbeforeunload = mytest(); &lt;/script&gt; &lt;apex:form id="form"&gt;    &lt;apex:pageblock title="Member List" &gt;  &lt;apex:pageBlocktable value="{!CheckSelectedList}" var="memLst" &gt; &lt;apex:column title="Select" &gt; &lt;apex:inputCheckbox value="{!memLst.checked}" &gt;&lt;/apex:inputcheckbox&gt; &lt;/apex:column&gt; &lt;apex:column headerValue="Name" &gt; &lt;apex:actionRegion &gt; &lt;apex:outputField value="{!memLst.KeepSelected.Name}" &gt; &lt;apex:inlineEditSupport event="ondblClick" showOnEdit="btnSave,btnCancel" hideOnEdit="btnAddSession" /&gt; &lt;/apex:outputField&gt; &lt;/apex:actionRegion&gt; &lt;/apex:column&gt;  &lt;/apex:pageBlocktable&gt;  &lt;apex:pageblockButtons&gt; &lt;apex:commandButton value="Save" action="{!save}" id="btnSave"  style="display:none" /&gt;  &lt;apex:commandButton value="Cancel" action="{!cancel}" id="btnCancel"  style="display:none" reRender="PanelId" /&gt; &lt;/apex:pageblockButtons&gt;   &lt;/apex:pageblock&gt; &lt;/apex:form&gt; &lt;/apex:page&gt;   In my VF Page, I have a in-line edit support enable.  The issue is:  Whenever, I want to alert user when they edit records and navigate without saving the record using JavaScript (Please see above the JavaScript code I was trying). It doesn't seem to be working. Am I missing anything? Is it possible to do this using only JavaScript in Customer Visual Force Page? Need: I want when user edit the Record and leave the page without saving my function will execute and show the pop-up message.   My thoughts:  I was also thinking to execute my JavaScript function by using apex class? Should it be possible? Or any other technique how to invoke popup when the user navigate without saving the Edit records?
73868
I need help. I am currently trying to test this code before uploading  public class CoreValuesExt { ApexPages.StandardController sc; public boolean readonly {get; set;} public Core_Values__c cv {get; set;} public integer countEdit = 1; public string buttonValue {get; set;} public integer recordScan;  public CoreValuesExt(ApexPages.StandardController sc) {     this.sc = sc;     cv = new Core_Values__c();     cv.Account__c = sc.getid();      readonly = true;     buttonValue = 'Edit';     recordScan = [SELECT COUNT() FROM Core_Values__c WHERE Account__c = :cv.Account__c];    if (recordScan != 0){    cv = [SELECT id, HSE__c, Professionalism_Integrity__c, Quality_Accuracy__c, Technology_Innovation__c, Timeliness__c, Value_for_money__c FROM Core_Values__c WHERE Account__c = :cv.Account__c];     }  }  public ApexPages.PageReference Save() {     return sc.Save(); }  public void ApplyAction() {     countEdit++;     Integer modolus = Math.mod(countEdit, 2);     String total = cv.HSE__c + cv.Professionalism_Integrity__c + cv.Quality_Accuracy__c + cv.Technology_Innovation__c + cv.Value_for_Money__c + cv.Timeliness__c;     if(modolus == 0)     {         readonly = false;         buttonValue = 'Save';     }     else     {         if(total != 'nullnullnullnullnullnull')            {         if (recordScan == 0){         insert cv;         readonly = true;         buttonValue = 'Edit';         }         else         {         update cv;         readonly = true;         buttonValue = 'Edit';         }         }     }    }   }  With this trigger.  trigger CoreValuesTrigger on Core_Values__c (before insert) {  Core_Values__c cvs = Trigger.new; CoreValuesExt.ApplyAction(cvs);  }   But when I try to save, I get a message saying:      Illegal assignment from List to   CoreValuesExt__Core_Values__c at line 3 column 1   "  How do I go through with this? I need help. Thanks
62871
If my html looked like this:  &lt;td class="controlCell"&gt;     &lt;input class="inputText" id="SearchBag.CompanyName" name="SearchBag.CompanyName" type="text" value="" /&gt; &lt;/td&gt;   How could I select #SearchBag.CompanyName with JQuery? I can't get it to work and I fear it's the dot that's breaking it all. The annoying thing is that renaming all my id's would be a lot of work, not to mention the loss in readability.  Note: Please let's not start talking about how tables are not made for lay-outing. I'm very aware of the  and try hard to use it as much as possible.
100032
How exactly do you make an auto-refreshing div with JavaScript (specifically, jQuery)?  I know about the setTimeout method, but is it really a good practice ? Is there a better method?  function update() {     $.get("response.php", function(data) {         $("#some_div").html(data);     });     window.setTimeout("update();", 10000); }
17427
I'm porting a module that currently works with Blocks/BlockForms to Paragraphs/NodeForms. I'm inserting an embedded form inside a Paragraph inside a Node Edit page using a hook_field_widget_entity_reference_paragraphs_form_alter. The general structure where the form gets inserted is: $form['field']['widget'][0]['settings'][form here]  After this the form displays as expected on the node edit page. The inserted form goes through a number of #process steps. The element in question is a select form that when the button underneath it is pressed, is supposed to retrieve some data via a custom submit handler and place it on the page with ajax:  The array for this element looks like this:  You can see the custom submit handler that is supposed to fire when 'Select Segment Set' is pressed After debugging, I've found that the entire NodeForm appears to be submitted to the backend, and the only handler that is found is from some other field that uses ajax. In short 'updateSegmentSet' is never discovered as a submit handler. When I debug the original module based on block/blockforms, I do see the correct submit handler being discovered. Now in the latter case, of course a blockForm is submitted to the back end with the correct plugin. Given that this is basically a form within a form within a form, is there something special I have to do to get the custom submit handler to run? I've read a few things online e.g. the 'settings' key and '#tree' = true. EDIT The Ajax property looks like this:       '#ajax' =&gt; [         'callback' =&gt; [$this, 'updateSegmentSetAjax'],         'wrapper' =&gt; $wrapper_id,       ],    public function updateSegmentSetAjax(array &amp;$form, FormStateInterface $form_state) {     $button = $form_state-&gt;getTriggeringElement();     // Go one level up in the form, to the widgets container.     return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));   }  As best I can tell, this is never called either.
91485
So this is my controller which create new event and save event.  in this i have hardcoded page redirect link  '/a3I/o'. i dnt want this to hardcoded. I want to do something like it will redirect to that tab without harcoded code or this will redirect to new record page which i am creating in this code(t1).   public class ERFormController {     public Event_Request__c t1{get;set;}      public ERFormController(ApexPages.StandardController controller)     {         t1 = new Event_Request__c();     }      public PageReference save()     {         insert t1;          ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));         PageReference pg = new PageReference('/a3I/o');         pg.setRedirect(true);         return pg;       }
59846
In the following example code, I attach an onclick event handler to the span containing the text "foo". The handler is an anonymous function that pops up an alert().  However, if I assign to the parent node's innerHTML, this onclick event handler gets destroyed - clicking "foo" fails to pop up the alert box.  Is this fixable?  &lt;html&gt;  &lt;head&gt;  &lt;script type="text/javascript"&gt;    function start () {     myspan = document.getElementById("myspan");     myspan.onclick = function() { alert ("hi"); };      mydiv = document.getElementById("mydiv");     mydiv.innerHTML += "bar";   }   &lt;/script&gt;  &lt;/head&gt;   &lt;body onload="start()"&gt;    &lt;div id="mydiv" style="border: solid red 2px"&gt;      &lt;span id="myspan"&gt;foo&lt;/span&gt;    &lt;/div&gt;  &lt;/body&gt;  &lt;/html&gt;
97763
This is the first time I've ever tried to load a view using Ajax in Drupal7 and I would be appreciated if you help me from scratch. I've spent hours to learn how to do this but I still failed!  I created a view called image_gallery, it has three blocks called hd,tablet and phone and it displays set of images.I created a tab and I want to display and load these blocks (generally views) with Ajax. this my HTML:      &lt;div&gt;         &lt;div id="image_gallery_tab"&gt;             &lt;ul&gt;                 &lt;li id="igt1"&gt;HD&lt;/li&gt;                 &lt;li id="igt2"&gt;Tablet&lt;/li&gt;                 &lt;li id="igt3"&gt;Cellphone&lt;/li&gt;             &lt;/ul&gt;         &lt;/div&gt;         &lt;div id="image_gallery_content"&gt;             &lt;div class="igc" id="igc1"&gt;                 &lt;?php print views_embed_view("image_gallery","hd") ?&gt;             &lt;/div&gt;             &lt;div class="igc" id="igc2"&gt;             &lt;/div&gt;             &lt;div class="igc" id="igc3"&gt;             &lt;/div&gt;         &lt;/div&gt;     &lt;/div&gt;   I set the Use Ajax to "yes" in the views UI. this is my jQuery code:  $("#image_gallery_tab ul li").click(function(){         var id = $(this).attr("id").slice(-1);         $(".igc").css("display","none");         if(id==2)             {             $.ajax({                 url: Drupal.settings.basePath + 'views/ajax',                 type: 'POST',                 dataType: 'json',                 data: 'view_name=image_gallery&amp;view_display_id=tablet', // Pass a key/value pair.                 success: function(response) {                   $("#igc2").innerHTML=response.display;                 },                 error: function(data) {                  alert('An error occured!');                 }               });             }     });   but it displays nothing. what is wrong here and what shall I do? thanks
66558
I have seen the following methods of putting JavaScript code in an &lt;a&gt; tag:  function DoSomething() { ... return false; }    &lt;a href="javascript:;" onClick="return DoSomething();"&gt;link&lt;/a&gt; &lt;a href="javascript:DoSomething();"&gt;link&lt;/a&gt; &lt;a href="javascript:void(0);" onClick="return DoSomething();"&gt;link&lt;/a&gt; &lt;a href="#" onClick="return DoSomething();"&gt;link&lt;/a&gt;   I understand the idea of trying to put a valid URL instead of just JavaScript code, just in case the user doesn't have JavaScript enabled. But for the purpose of this discussion, I need to assume JavaScript is enabled (they can't login without it).  I personally like option 2 as it allows you to see what's going to be run&ndash;especially useful when debuging where there are parameters being passed to the function. I have used it quite a bit and haven't found browser issues.  I have read that people recommend 4, because it gives the user a real link to follow, but really, # isn't "real". It will go absolutely no where.  Is there one that isn't support or is really bad, when you know the user has JavaScript enabled?  Related question: .
80540
I'm trying to do some treatement after creating an item but the treatement is done twice because in my code after creating the item, I'm updating it , so the event reciever get fired twice: first when I add the element and the second when I updated it. Here's the code :  if (Mode == OperationMode.New) {     item = ListeActions.AddItem();     item["Client"] = new SPFieldLookupValue(myClient.ID, myClient["Name"] as string).ToString();     //the Event Reciever ItemAdded is fired here } if (Mode == OperationMode.Edit) {     item = ListeActions.GetItemById(ActionItemID); } TextField ACObject = (TextField)Page.GetControlById("ACObjectID"); UserField ACAssignedTo = (UserField)Page.GetControlById("ACAssignedToID"); NoteField ACDetails = (NoteField)Page.GetControlById("ACDetailsID");  item["Object"] = ACObject.Value; item["AssignedTo"] = ACAssignedTo.Value; item["Details"] = ACDetails.Value;  item.Update();  //if we're in the case of adding new item then the event //reciever ItemAdded is fired here for the second time //while ItemUpdated is not fired   So how can I stop the second fire of itemAdded resulting on the item.Update() yet keep the first fire since I need to keep applying my treatement?  PS: in the case of updating an existing ListeActions.item the itemUpdated is fired twice too !!  BTW : This Code isn't written in the itemadded method nor in the itemupdated method, actually it's the code in a user control for a webpart development.
46962
Is there some easy way to handle multiple submit buttons from the same form? For example:  &lt;% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %&gt; &lt;input type="submit" value="Send" /&gt; &lt;input type="submit" value="Cancel" /&gt; &lt;% Html.EndForm(); %&gt;   Any idea how to do this in ASP.NET Framework Beta? All examples I've googled for have single buttons in them.
88408
I have this Visualforce code snippet in a page:  &lt;apex:outputLink value="javascript:if (window.confirm('Are you sure?')) DeleteQuoteLineItem('{!LineItem.QuoteLineItem.Id}');"&gt;     Del &lt;/apex:outputLink&gt;  &lt;apex:actionFunction action="{!DeleteQuoteLineItem}" name="DeleteQuoteLineItem" reRender="content"&gt;     &lt;apex:param value="test"/&gt; &lt;/apex:actionFunction&gt;   The two methods I'm using for testing are:  public void DeleteQuoteLineItem(String RecordID) {     System.debug('method with a paramater');     System.debug(RecordID); }  public void DeleteQuoteLineItem() {     System.debug('method without a parameter'); }   Everytime I click on the link to execute the apex:actionFunction, it's calling the DeleteQuoteLineItem() method without any parameter. I looked online and it seems like I need to create a class attribute and use assignTo= in my apex:param to populate it accordingly.  Is it possible to prevent this behavior and use standard method parameters, so I don't have to create class attributes? I want to work on a clean and optimized codebase, preventing unnecessary variable scope (so no class attribute when it's not required) and improve code re-usability by staying context agnostic.  Thanks
76281
I want to do a Response.Redirect("MyPage.aspx") but have it open in a new browser window. I've done this before without using the JavaScript register script method. I just can't remember how?