How to access the controller method from javascript onclick event?

Hi All,
   I am totally new to development. And I got struck in calling a controller method from javascript function.
   I have no idea about ajax and all those things. Please can anyone help me to solve this issue!
Thanks in advance.

Hi,
As I know, you can use jQuery to do this, here is an example.
Example of your Controller Method.
[HttpPost] // can be HttpGet
public ActionResult Test(string id)
bool isValid = yourcheckmethod(); //.. check
var obj = new {
valid = isValid
return Json(obj);
and this would be your javascript function.
function checkValidId(checkId)
$.ajax({
url: 'controllerName/Test',
type: 'POST',
contentType: 'application/json;',
data: JSON.stringify({ id: checkId }),
success: function (valid)
if(valid) { //show that id is valid }
else { //show that id is not valid }
If you have further issues, I would suggest you move to MVC forum, it is appropriate and more experts will assist you.
Best Regards,
Jambor
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • How to call jpf controller method from javascript

    Can any one help me how to call pageflow controller method from JavaScript.\
    Thanks.

    Accessing a particular pageflow method from Javascript is directly not possible unless we do some real funky coding in specifying document.myForm.action = xyz...Heres what I tried and it did not work as expected: I found another workaround that I will share with you.
    1. In my jsp file when I click a button a call a JavaScript that calls the method that I want in pageflow like this: My method got invoked BUT when that method forwards the jsp, it lost the portal context. I saw my returned jsp only on the browser instead of seeing it inside the portlet on the page of a portal. I just see contents of jsp on full browser screen. I checked the url. This does make the sense. I do not see the url where I will have like test1.portal?_pageLabe=xxx&portlet details etc etc. So this bottom approach will notwork.
    document.getElementById("batchForm").action = "/portlets/com/hid/iod/Batches/holdBatch"; // here if you give like test1.portal/pagelable value like complete url...it may work...but not suggested/recommended....
    document.getElementById("batchForm").submit;
    2. I achieved my requirement using a hidden variable inside my netui:form tag in the jsp. Say for example, I have 3 buttons and all of them should call their own action methods like create, update, delete on pageflow side. But I want these to be called through javascript say for example to do some validation. (I have diff usecase though). So I created a hidden field like ACTION_NAME. I have 3 javascript functions create(), update() etc. These javascripts are called onclick() for these buttons. In thse functions first I set unique value to this hiddent field appropriately. Then submit the form. Note that all 3 buttons now go to same common action in the JPF. The code is like this.
    document.getElementById("ACTION_NAME").value = "UPDATE";
    document.getElementById("batchForm").submit.
    Inside the pageflow common method, I retriev this hidden field value and based on its value, I call one of the above 3 methods in pageflow. This works for me. There may be better solution.
    3. Another usecase that I want to share and may be help others also. Most of the time very common usecase is, when we select a item in a drop bos or netui:select, we want to invoke the pageflow action. Say we have 2 dropdown boxes with States and Cities. Anytime States select box is changed, it should go back to server and get new list of Cities for that state. (We can get both states and cities and do all string tokenizer on jsp itself. But inreality as per business needs, we do have to go to server to get dynamic values. Here is the code snippet that I use and it works for all my select boxes onChange event.
    This entire lines of code should do what we want.
    <netui:anchor action="selectArticleChanged" formSubmit="true" tagId="selectPropertyAction"/>                    
    <netui:select onChange="document.getElementById(lookupIdByTagId('selectPropertyAction',this )).onclick();" dataSource="pageFlow.selectedArticleId" >
    <c:forEach items="${requestScope.ALL_ARTICLE}" var="eachArticle">
    <%-- workshop:varType="com.hid.iod.forms.IoDProfileArticleRelForm" --%>
    <netui:selectOption value="${eachArticle.articleIdAsString}">${eachArticle.articleItemName}</netui:selectOption>
    </c:forEach>               
    </netui:select>
    See if you can build along those above lines of code. Any other simpler approches are highly welcome.
    Thanks
    Ravi Jegga

  • How to call a bean method from javascript event

    Hi,
    I could not find material on how to call a bean method from javascript, any help would be appreciated.
    Ralph

    Hi,
    Basically, I would like to call a method that I have written in the page java bean, or in the session bean, or application bean, or an external bean, from the javascript events (mouseover, on click, etc...) of a ui jsf component. I.e., I would like to take an action when a user clicks in a column in a datatable.
    Cheers,
    Ralph

  • OOABAP-How to access the protected methos from a class

    How to access the protected methos from a class..There is a built in class..For tht class i have created a object..
    Built in class name : CL_GUI_TEXTEDIT
    method : LIMIT_TEXT.
    How to access this..help me with code

    hi,
    If inheritance is used properly, it provides a significantly better structure, as common components only
    need to be stored once centrally (in the superclass) and are then automatically available to subclasses.
    Subclasses also profit immediately from changes (although the changes can also render them invalid!).
    Inheritance provides very strong links between the superclass and the subclass. The subclass must
    possess detailed knowledge of the implementation of the superclass, particularly for redefinition, but also in
    order to use inherited components.
    Even if, technically, the superclass does not know its subclasses, the
    subclass often makes additional requirements of the superclass, for example, because a subclass needs
    certain protected components or because implementation details in the superclass need to be changed in
    the subclass in order to redefine methods.
    The basic reason is that the developer of a (super)class cannot
    normally predict all the requirements that subclasses will later need to make of the superclass.
    Inheritance provides an extension of the visibility concept: there are protected components. The visibility of
    these components lies between that of the public components (visible to all users, all subclasses, and the class itself), and private (visible only to the class itself). Protected components are visible to and can be used by all subclasses and the class itself.
    Subclasses cannot access the private components  particularly attributes) of the superclass. Private
    components are genuinely private. This is particularly important if a (super)class needs to make local
    enhancements to handle errors: it can use private components to do this without knowing or invalidating
    subclasses.
    Create your class inse24 and inherit this CL_GUI_TEXTEDIT
    class in yours. You can then access the protected methods.
    Hope this is helpful, <REMOVED BY MODERATOR>
    Edited by: Runal Singh on Feb 8, 2008 1:08 PM
    Edited by: Alvaro Tejada Galindo on Feb 19, 2008 2:19 PM

  • How to access the abap program from MS Excel?

    Hi ,
    How to access the abap program from MS Excel or MS access ?
    The abap program "z..."  has the below input and output attributes
    Input : Date,Index and file name with location (.htm or .xls)
    Output : htm or xls file downloaded at the above location.
    Please help me here.Do we haev to use BAPI and RFC?If yes,please tell me how to use them
    Regards
    Dinesh

    Maybe this could help you up -;)
    [Simple SE38 Emulator using Microsoft Excel|Simple SE38 Emulator using Microsoft Excel]
    Greetings,
    Blag.

  • How to access Custom Controller Methods and context

    Hi
    I have to components (comp1,comp2) in one DC.  I want to use custom controller method of comp1 into comp2 view?
    Thanks
    Prasad

    Hi,
    in order to access comp1 from comp2.
    create Public part for Comp1 and it to the useds DC of Comp2 and as well add the required controllers in Comp2 (in view controller and custome controller where u want to access them).
    PFB link fro example.
    [http://wiki.sdn.sap.com/wiki/display/WDJava/UsecomponentsinbiggerWebDynproprojects+%28componentization%29]
    Regards,
    Govindu

  • Accessing a public method from javascript in an applet!!!

    Hi!!
    I'm have an applet (named say applet.class) in an html page that has a public method like this....
    public void doShowFrame()
              Frame frame = new frame();
         frame.setVisible (true);
    What I want to do is to call that method with javascript, I've tried to do it like this...
    function show(){
    applet.doShowFrame();
    But when i press the button that launch the java scipt the browser says
    'applet' is unidentified...
    What's wrong, what can I do??

    http://www.google.com/search?q=applet+javascript+communication&sourceid=opera&num=0&ie=utf-8&oe=utf-8
    how hard was that? seriously.

  • How to access the MDX application from SQL server when working with OBIEE?

    Hi,
    I am new to MS SQL Server 2005. We have developed the OLAP Cubes on SQL Server Business Intelligence Development Studio with its integration with Oracle Business Intelligence Enterprise Edition (OBIEE).
    The backend query is in MDX language. Now if I need to run that query I need to access the MDX Application, rite?
    So need to know how to connect to MDX application.
    Regards,

    Administration Tool: File - Import - "from multidimensional". There you choose "Provider Type" = "Analysis Server 2005". You specify the URL, user name and password. Then you can import MSAS cubes just like Essbase ones.
    Cheers

  • How to access the MDX application from SQL server?

    Hi,
    I am new to MS SQL Server 2005. We have developed the OLAP Cubes on SQL Server Business Intelligence Development Studio with its integration with Oracle Business Intelligence Enterprise Edition (OBIEE).
    The backend query is in MDX language. Now if I need to run that query I need to access the MDX Application, rite?
    So need to know how to connect to MDX application.
    Regards,

    I think that you have posted this query to the wrong forum. Try this one:
    Business Intelligence Suite Enterprise Edition
    --Andy                                                                                                                                                                                                                                                                                           

  • How to access the private method

    All,
    I have class ABC with private method getfilename().
    I want to use this private method ...
    Is it possible to use this method without inheritence ?
    Is it possible to access this private method using annoymous inner class ?
    or any other alternatives ??
    namanc

    I have class ABC with private method getfilename().
    I want to use this private method ... You can't; it's private to the instantiations of that class.
    Is it possible to use this method without inheritence ? No, no even with inheritance.
    Is it possible to access this private method using
    annoymous inner class ? Nope, unless you can write that anonymous inner class yourself.
    or any other alternatives ?? Nope; privvy parts are privvy parts and only the owner of those privvy
    parts can touch them. (ahem)
    kind regards,
    Jos
    ps. unless you want to do reflection surgery of course.

  • How do I share the Photo Library on my desktop with another User. I have Apoerture set up on my wife's user account but cannot figure out how to access the photo library from her desktop.

    I just got a new IMac. I transferred all the photos from our old PC to the Aperture Library on my User account. My wife is set up as another User. She can access Aperture from her User account but there are no photos in the Library. How can I share or giver her access to the photos so that she can work with them on Aperture from her User account?

    Move the Aperture library to separate disk or disk partition with plenty of space for all your photos. On a separate disk or partition it will be possible to set the "Ignore ownership on this volume" flag. Then two users can write to the same Aperture library without permission problems.
    The procedure is describe here for iPhoto libraries, but this will work for Aperture libraries as well:
    iPhoto: Sharing libraries among multiple users
    If you want to use a drive for your Aperture library, that has been used with a PC, format it for Mac, before you move the Aperture library there. This can be done with Disk Utility.

  • Accessing a japplet method from javascript using plugin

    Hi,
    I am currently trying to invoke a public method coded in a swing applet from my javascript.
    As per the documentation and discussion at this site,tried to workaround by using document.AppletName.MethodName.
    I am using Javaplugin 1.2.2 and an Object tag (not an applet tag)
    I am getting "object not found' error on running it.
    Any possible suggestions as to why its happening?

    part of my javascript code is pasted below.
    I tried using applet tag instaed just in case but keep gettin the same message.'Not an object"
    </HEAD>
    <BODY onload ="setUserName()">
    <SCRIPT LANGUAGE="javascript">
    function setUserName(){
    var str = document.location.search;
    document.write(str)
    var query = str.charAt(0) == '?' ? str.substring(1) : str;
    document.write(query)
    -----> document.BApplet.setUser(query);
    </script>
    BApplet will appear below in a Java enabled browser.<BR>
    <OBJECT id="BApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 100
              HEIGHT = 100
              ALIGN = middle
              VSPACE = 0
              HSPACE = 0
              codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">
    <PARAM NAME = CODE VALUE = "com.common.BApplet.class" >
    <PARAM NAME = CODEBASE VALUE = "./lib" >
    <comment>
    <embed>
    </embed>
    </comment>
    </object>
    </body>
    </html>

  • How can assign the value returned from javascript to Hidden item

    Hi All,
    I have created a report with button in one column adding following code to SQL select statement like
    SELECT USER_RQST_ID, USER_RQST_DESC, RQST_DATE, STATUS, USER_ID, CNTRY_ID, KPI_LIST, YEAR_LIST, QTR_LIST, MONTH_LIST,
    PROD_LIST, FULL_PERIOD_FLG, GEN_DATE, '<input type=button value="view_list" onclick="javascript:doSubmit('||USER_RQST_ID||');">' button FROM KPI_USER_RQST;
    Then i have implemet doSubmit() function in Javascript like
    function doSubmit(req_id)
    html_GetElement('HIDDEN_ITEM')= req_id.value;
    Here HIDDEN_ITEM is the name of the item, I want to use that HIDDEN_ITEM value in PL/SQL block like...
    BEGIN
    INSERT INTO SAMPLE(KEY) VALUES(:HIDDEN_ITEM);
    END;
    But it is not working, Please help me anybody know the solution How to assign an item in javascript block function.
    Thanks,
    Neel

    Hello,
    doSubmit() is one of the built in javascript functions in apex and it's a bad idea to override it unless you know exactly what you are doing, and even then is a generally bad idea.
    change your function to this
    function mySubmit(pValue){
    $x('HIDDEN_ITEM').value = pValue;
    doSubmit();
    then your onclick will look like this notice the lack of the javascript: and the three ''' quotes to get the proper quotations for your value.
    onclick="mySubmit('''||USER_RQST_ID||''')"
    And there you go
    Carl

  • How to access the database tables from application

    Hii all,
    The information in webcenter content, such as meta data fields, users, security groups etc are stored in
    database tables like-      Revisions, SecurityGroups, Users, DocType etc..
    Can we access this tables from an adf application or any webcenter application..
    If yes, then what can be the approach for that..??
    Another things, how can we create custom tables just like the predefined tables...??
    Any information regarding this.??
    Thanks

    Can we access this tables from an adf application or any webcenter application.Yes, you can - like to any other existing database. But I would strongly discourage you from any, but read-only access, or you can easily end up with inconsistent data.
    If yes, then what can be the approach for that..??Just create a database connection and define in your model what tables you want to access.
    Another things, how can we create custom tables just like the predefined tables...
    Actually, WebCenter Content provides functionality of creation of custom tables (see http://docs.oracle.com/cd/E23943_01/doc.1111/e10978/c04_metadata.htm#autoId2 ) and these are probably the only good candidates for read-write access. See further in the manual what use cases are supported. Of course, you could do this even externally, but rather than Data Definition Language, I'd use services (if there are some).

  • How to access the component id from another mxml?

    I tried to set the data to a DataGrid in another mxml, but the complier said there's a problem, like this:
    the components/FileDataGrid.mxml:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx" >
        <mx:DataGrid x="150" y="50" id="dgFile">       <mx:columns>
             <mx:DataGridColumn headerText="COL"/>
           </mx:columns>
        </mx:DataGrid>
    </s:Group>
    the main mxml:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
              xmlns:custom="components.*" layout="absolute">
         <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
         </fx:Declarations>
         <fx:Script>
              <![CDATA[
                   private function loadDG():void
                        var arrFile:Array= new Array("abc","123");
                        dgFile.dataProvider = arrFile;
                        trace( "The data has successfully loaded" );
              ]]>
         </fx:Script>
         <s:Button  x="300" y="50" label="Load"  click="loadDG()" />
         <custom:FileDataGrid/>
    </mx:Application>
    The compiling error is :
    Multiple markers at this line:
    -1120: Access of undefined property dgFile.
    -arrFile
    Anybody can tell me, how to achieve it?
    Thanks a lot!

    Hi, You cant access it like this. To access, first give some id to the custom component you have added.
    i.e
    <custom:FileDataGrid id="custFDG"/>
    Then you can acces it from script,
    custFDG.dgFile.dataProvider = arrFile;
    Hope this shud work fine.
    Thanks.
    Abhinav

Maybe you are looking for

  • Creative Mediasource Organizer Losing Year T

    I use Windows XP, Creative Mediasource Organizer version 3.30.35 and my player is a Zen MicroPhoto 8G. I have over 4000 MP3 files organized with id tags in Creative Mediasource Organizer. These are almost exclusivly?MP3 files that I recorded myself.

  • Plz meke me understand the given code!!!!!!

    Dear All, I am giving you the code below. Please any one can explain me the whole program and the purpose. specially form LOOP section to the end of the program. I will be very kind if someone will help to make me understood. Regards, Abhay. TABLES:b

  • Create new Master Repository - oracle technology exist in logical topology

    I have created a new master repository using the 'Create Master Repository' function in to an ORacle database user. This was all successful and I can sign in to topology manager as SUPERVISOR. However I notice that the physical topology includes the

  • Is the H.263 vedio extension enough and convenient...

    I want to buy Nokia 3120 but I am worried about the H.263 extension as it is the only one when comparing with other mobiles... What do you advice for that as I do not have enough experience and I do not want to be surprised in the future?

  • FCPX crashes in Mountain Lion

    Now that I've installed Mountain Lion on my MacBookPro, 4 gigs ram, 2.4 GHz, Core 2 Duo FCPX locks up on everything I try to do. There are no projects or events loaded thaks to Event Manager. Can't import from camera. Goes into "isn't respnding" mode