I have a JSP page where I have put a JS code for confirm() method. I am calling this from the form "onsubmit". The dialog box has 2 buttons "OK' and 'cancel'. On clicking "OK" the form should be submitted which is happening but on click of 'cancel' button I need to redirect the page to some other page. Below is the JS code.  function showDialog() {     if(confirm("Press OK to confirm")) {      console.log("Clicked OK, confirmation.");} else { console.log("Clicked Cancel, confirmation.");         }  Below is the form tag where I am calling JS function:  &lt;form:form  name="login" id="login" action="&lt;%=loginPass%&gt;" method="POST" autocomplete="off" onsubmit= "showDialog()"&gt;
906
How can I redirect the user from one page to another using jQuery or pure JavaScript?
41675
When interacting with different elements and applying multiple actions it  may be quite convenient in some situations if we could do:  WebElement myInput = driver.findElement(By.id("my-input-id")); myInput.clear().sendKeys("test");   Instead of:  WebElement myInput = driver.findElement(By.id("my-input-id")); myInput.clear() myInput.sendKeys("test");   But, the problem is , sendKeys() and other "action" methods cannot be chained as is - they return void and not the current WebElement.  What would be the easiest way to achieve chaining multiple actions?
72166
I have some HTML and jQuery that slides a div up and down to show or hide` it when a link is clicked:  &lt;ul class="product-info"&gt;   &lt;li&gt;     &lt;a href="#"&gt;YOU CLICK THIS TO SHOW/HIDE&lt;/a&gt;     &lt;div class="toggle"&gt;       &lt;p&gt;CONTENT TO SHOW/HIDE&lt;/p&gt;     &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;   $('div.toggle').hide(); $('ul.product-info li a').click(function(event){   $(this).next('div').slideToggle(200); }   My question is: How do I use preventDefault() to stop the link acting as a link and adding "#" to the end of my URL &amp; jumping to the top of the page?  I can't figure out the right syntax, I just keep getting an error saying      preventDefault() is not a function.
5826
I am using the  plugin  I am looking for way to refresh the page when in some circumstances when the dialog is closed.  Is there a way to capture a close event from the dialog?  I know I can run code when the close button is clicked but that doesn't cover the user closing with escape or the x in the top right corner.
45495
I opened a Popup from an inline VF page in SFDC and then after some action I was able to close the window but needed a refresh of the Top window from inline frame .  My code is as below for opening a pop up.Note this is inline page   &lt;apex:page standardController="Account" extensions="Accountctrl"&gt;  &lt;apex:form &gt;  &lt;script&gt;    function openwindow(){       window.open("/apex/pagereal", "myWindow", "width=200, height=100");    }  &lt;/script&gt;  &lt;apex:pageBlock &gt;  &lt;apex:pageBlockSection columns="1" id="Test" &gt;     &lt;apex:inputcheckbox value="{!test.istest__c}" label="Same as Above"&gt;     &lt;apex:actionSupport event="onchange" rerender="Test" /&gt; &lt;/apex:inputcheckbox&gt;   &lt;apex:outputPanel rendered="{!NOT(test.istest__c)}"&gt;  &lt;apex:inputField value="{!test.Campaign__c}" /&gt; &lt;apex:inputField value="{!test.cust_vendor__c}" /&gt; &lt;/apex:outputPanel&gt; &lt;apex:commandButton value="Tetete" onclick="openwindow();"/&gt;   &lt;/apex:pageBlockSection&gt;  &lt;/apex:form&gt; &lt;/apex:page&gt;   And my popup page code is as below and I want to redirect top frame from inline page  &lt;apex:page &gt;    &lt;script&gt;    function test(){      alert('hello');      window.opener.top.location.href='https://googleflowauth-dev- ed.my.salesforce.com/001900000096agv';   }     &lt;/script&gt;    &lt;apex:form &gt;     &lt;!-- End Default Content REMOVE THIS --&gt;      &lt;apex:commandButton onclick="test()" value="Test"/&gt;     &lt;/apex:form&gt;   The error is pretty much I know that it is for security browsers dont allow        Unsafe JavaScript attempt to initiate navigation for frame with URL '' from frame with URL ''. The frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener.   I am happy if i get workaround for same
73078
Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form? The submit button is not there. I am using a custom div instead of that.
81052
// Insert an account  Account a = new Account(Name='Test',                      annualRevenue=100.0);  insert a;  // Create an approval request for the account Approval.ProcessSubmitRequest req1 =        new Approval.ProcessSubmitRequest(); req1.setObjectId(a.id); req1.setNextApproverIds(new Id[] {'***************'}); // Submit the approval request for the account Approval.ProcessResult result =                     Approval.process(req1);   Am trying to execute this code in anonymous block. How ever when tried in trigger i got same error all the time. Hard coded next approvers ID. No luck.  Any suggestions on what am I doing wrong ? Please help!!
65851
Is there a well-supported, common behavior that I can expect if I do something like this in HTML:  &lt;form method="get" action="/somePage.html?param1=foo&amp;param2=foo"&gt;   &lt;input name="param2"&gt;&lt;/input&gt;   &lt;input name="param3"&gt;&lt;/input&gt; &lt;/form&gt;   Seems like this sort of thing is inherently ridiculous, but I've seen it used here and there and I was wondering what on Earth the expected behavior should be.  Are browsers smart enough to tack on "&amp;param2=whatever&amp;param3=whatever" to the action, or do they just throw in a second question mark?  Or what?  Are there cases where this is actually the right way to do things?
80369
I want to create one SP dialogue box at home page which load the new item form of list or survey if current login user is not created any item previously.  Is there any way to do that ?  I tried using query but it takes time to load data.  My Code is as below :  &lt;script type="text/javascript"&gt; ExecuteOrDelayUntilScriptLoaded(init,'sp.js'); var context; var web; var user; var siteUrl = _spPageContextInfo.siteServerRelativeUrl ; //var userId= _spPageContextInfo.userId; var userId= 123; var flag=true; //var options = { title: "Announcements - New Item",url:"../Lists/Announcements/NewForm.aspx"}; var options = { title: "Announcements - New Item",url:"http://webtest:3333/Lists/test/NewForm.aspx"};  function init() { context = SP.ClientContext.get_current(); web = context.get_web(); //alert(flag); getCurrentUser(); retrieveListItems();  }  function getCurrentUser() { user = web.get_currentUser(); context.load(user); context.executeQueryAsync(onGetUserNameSucces, onGetUserNameFail); } function onGetUserNameSucces() { // TODO: implement your own succes handler     //alert(user.get_title()); } function onGetUserNameFail(sender, args) { // TODO: implement your own fail handler and do some logging }  function retrieveListItems() {       var oList = context.get_web().get_lists().getByTitle("test");      var camlQuery = new SP.CamlQuery();       //context.load(user);      //alert(userId);  camlQuery.set_viewXml('&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\'Author\' /&gt;&lt;Value Type=\'User\'&gt;'+ user.get_title() +'&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;');     this.collListItem = oList.getItems(camlQuery);      context.load(collListItem);     context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));   }  function onQuerySucceeded(sender, args) {            //alert( _spPageContextInfo.userId);      var listItemInfo = '';     var listItemEnumerator = collListItem.getEnumerator();       while (listItemEnumerator.moveNext()) {         var oListItem = listItemEnumerator.get_current();         listItemInfo += '\nID: ' + oListItem.get_id() +              '\nTitle: ' + oListItem.get_item('Title');     }     alert(listItemInfo.toString());     if(listItemInfo==null){ //      flag='false';       SP.UI.ModalDialog.showModalDialog(options);            }      //alert(flag);        }  function onQueryFailed(sender, args) {     alert('Error: ' + args.get_message() + '\n' + args.get_stackTrace()); } &lt;/script&gt;   I cant get result in the data
53268
I am working on a web application (J2EE) and I would like to know the options that are available for handling a double post from the browser.  The solutions that I have seen and used in the past are all client-side:   Disable the submit button as soon as the user clicks it. Follow a POST-Redirect-GET pattern to prevent POSTs when the user clicks the back button. Handle the onSubmit event of the form and keep track of the submission status with JavaScript.   I would prefer to implement a server side solution if possible. Are there any better approaches than the ones I have mentioned above, or are client-side solutions best?
18317
I'm running into a problem where a user can submit any form built by the Form API multiple times (fast clicking resulting in multiple requests).  I've put in the basic client side (javascript) solution of disabling the button, but I'm curious what the best approach to preventing this situation is on the server side.  Is there a recommended way to use Drupal's form token system to handle this?  Especially a global form solution (ie, adding a custom validator to every form using hook_form_alter()).  My approach so far has been something like this:  function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {   $form['#validate'][] = 'mymodule_form_validate'; }  function mymodule_form_validate(&amp;$form, &amp;$form_state){   //initialize form array   if (!isset($_SESSION['submitted_forms'])){     $_SESSION['submitted_forms'] = array();   }    $form_token = $form_state['values']['form_token'];   if ( isset($_SESSION['submitted_forms'][$form_token]) &amp;&amp; $_SESSION['submitted_forms'][$form_token] = TRUE ){     form_set_error('name]', 'This form has already been submitted');   }   else{     $_SESSION['submitted_forms'][$form_token] = TRUE;   } }   I'm running into trouble where the form_token isn't unique to the form - it seems to stay the same no matter what happens.  I'm probably misunderstanding what the token is in the grand scheme of the form api.  Any insight is appreciated!
53497
Is it possible to call a function from PHP using onsubmit from JavaScript? If so could someone give me an example of how it would be done?  function addOrder(){     $con = mysql_connect("localhost", "146687", "password");     if(!$con){         die('Could not connect: ' . mysql_error())     }      $sql = "INSERT INTO orders ((user, 1st row, 2nd row, 3rd row, 4th row)     VALUES ($session-&gt;username,1st variable, 2nd variable, 3rd variable, 4th variable))";      mysql_query($sql,$con)     if(mysql_query($sql,$con)){         echo "Your order has been added";     }else{         echo "There was an error adding your order to the databse: " . mysql_error();     } }   That's the function I am wanting to call. Its an ordering system, you type in how much of each item you want, hit submit and it should add the order to the table.
75034
I have an input form that lets me select from multiple options, and do something when the user changes the selection. Eg,  &lt;select onChange="javascript:doSomething();"&gt;   &lt;option&gt;A&lt;/option&gt;   &lt;option&gt;B&lt;/option&gt;   &lt;option&gt;C&lt;/option&gt; &lt;/select&gt;   Now, doSomething() only gets triggered when the selection changes.  I want to trigger doSomething() when the user selects any option, possibly the same one again.  I have tried using an "onClick" handler, but that gets triggered before the user starts the selection process.  So, is there a way to trigger a function on every select by the user?  Update:  The answer suggested by Darryl seemed to work, but it doesn't work consistently. Sometimes the event gets triggered as soon as user clicks the drop-down menu, even before the user has finished the selection process!
15800
Well I am trying to submit a form by pressing enter but not displaying a submit button. I don't want to get into JavaScript if possible since I want everything to work on all browsers (the only JS way I know is with events).  Right now the form looks like this:  &lt;form name="loginBox" target="#here" method="post"&gt;     &lt;input name="username" type="text" /&gt;&lt;br /&gt;     &lt;input name="password" type="password" /&gt;     &lt;input type="submit" style="height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" /&gt; &lt;/form&gt;   Which works pretty well. The submit button works when the user presses enter, and the button doesn't show in Firefox, IE, Safari, Opera and Chrome. However, I still don't like the solution since it is hard to know whether it will work on all platforms with all browsers.  Can anyone suggest a better method? Or is this about as good as it gets?
56044
It appears that the recent UI change for the close vote review dialog introduced a bug when it concerns suggested dupes. Reproducing in Firefox 78.0.1 (Mac OS). In this dialog there are two tabs, &quot;Question&quot; that shows the question to be closed, and &quot;Duplicate&quot; that shows the suggested duplicate. When the latter tab is active, the &quot;Close&quot; button produces no action though it is not disabled.  Only when on the &quot;Question&quot; tab can you successfully vote to close the question.   There seems to be an uncaught exception raised by JQuery, when called from review.en.js:  SyntaxError: Document.querySelectorAll: '.close-question-link[data-questionid=63380604]' is not a valid selector  Looks like the original question ID may be lost when switching to the &quot;Duplicate&quot; tab.
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.
15466
&lt;apex:page standardController="Employee__c" extensions="testPage" id="p"&gt; &lt;apex:form id="f"&gt;        &lt;div&gt;         &lt;input type="radio" name="acc" value="Existing" checked="checked"                 onclick="show(true, false);"&gt;Existing&lt;/input&gt;         &lt;input type="radio" name="acc" value="NEWAcc"                 onclick="show(false, true);"&gt;New&lt;/input&gt;     &lt;/div&gt;     &lt;apex:pageBlock id="pb1" title="Pg Block 1"&gt;     &lt;apex:pageBlockButtons &gt;  &lt;apex:commandButton value="save" action="{!saving}"/&gt;    &lt;/apex:pageBlockButtons&gt;     &lt;apex:pageBlockSection columns="1"&gt;    &lt;apex:inputField value="{!pme.Name}" /&gt;    &lt;apex:inputField value="{!pme.Address__c}"/&gt;       &lt;apex:inputField value="{!pme.Phone__c}"/&gt; &lt;apex:inputField value="{!pme.type__c}"/&gt;     &lt;/apex:pageBlockSection&gt;     &lt;/apex:pageBlock&gt;     &lt;apex:pageBlock id="pb2" title="Pg Block 2"&gt;     &lt;apex:pageBlockButtons &gt;  &lt;apex:commandButton value="save" action="{!saving}"/&gt;   &lt;/apex:pageBlockButtons&gt;     &lt;apex:pageBlockSection columns="1"&gt;    &lt;apex:inputField value="{!pme.Name}" /&gt; &lt;apex:inputField value="{!pme.Job_Title__c}"/&gt;    &lt;apex:inputField value="{!pme.Salary__c}"/&gt;    &lt;apex:inputField value="{!pme.type__c}"/&gt;     &lt;/apex:pageBlockSection&gt;     &lt;/apex:pageBlock&gt; &lt;/apex:form&gt;    &lt;script&gt; function show(showPb1, showPb2) {     // Match Visualforce's prefixing pattern     document.getElementById('p:f:pb1').style.display = showPb1 ? 'block' : 'none';     document.getElementById('p:f:pb2').style.display = showPb2 ? 'block' : 'none'; } show(true, false); &lt;/script&gt; &lt;/apex:page&gt;   Controller  public with sharing class testPage { public string Existing{get; set;} public string NEWAcc{get; set;} public Boolean radioexisting{get; set;} public Boolean radionew{get; set;} public Employee__c pmepme{get;set;} List&lt;SelectOption&gt; ownershipValues;     public Employee__c emp{get;set;}     public Employee__c pme{get;set;}     public Employee__c emplist{get;set;}     public String var {get;set;}         public boolean editSection {get;set;}          public testPage(ApexPages.StandardController controller) {         radioexisting=true;         radionew=false;             Employee__c emp=new Employee__c();             pme=(Employee__c )controller.getRecord();             editSection =true;             var= ApexPages.currentPage().getParameters().get('Id');              system.debug('erecrrrtrtrt');                  system.debug('erecrrrtrtrt'+NEWAcc);             if(var!=null){             emplist=[select Name,Address__c,Phone__c,Job_Title__c,Salary__c,type__c  From Employee__c where id=:var];             }             }          public PageReference saving(){                         system.debug('erecrrrtrtrt'+Existing);                  system.debug('erecrrrtrtrt'+NEWAcc);             upsert pme;             PageReference p=new PageReference ('/'+pme.id);             p.setRedirect(true);             return p;             }     public PageReference pbBlockRender() {     return null;     }     public PageReference EdittheSection (){ editSection = true; PageReference pf=new PageReference('https://c.ap2.visual.force.com/apex/test6');  pf.setredirect(true); return pf;           }      public String mypbBlock { get; set; } }   iam getting the following please help to fix it     System.SObjectException: SObject row was retrieved via SOQL without   querying the requested field: Employee__c.Name