Alpha Video Training
Results 1 to 8 of 8

Thread: JSON onClick function to set a value into textarea

  1. #1
    Member
    Real Name
    M
    Join Date
    Oct 2012
    Posts
    115

    Default JSON onClick function to set a value into textarea

    Dear all,
    I been doing a small application and got stacked here.
    I have a menu that works with JSON data, but i would like to implement a click event for a menu that SET a VALUE / INSERT VALUE in text-area control from the Menu selected value.

    Here is the line of code that needs FIX,
    {html: '<button class="{dialog.style}Button" </button>', onClick: function() { var var1 = {dialog.Object}.getValueFrom(this); {dialog.Object}.setValue('textarea', var1)}, value: 'a'};


    This is the full code FYI
    HTML Code:
    [
    	
    	{
    		type: 'radio-group',
    		variable: 'radioGroup1',
    		columns: 7, 
    		data: [
    				{html: '<button class="{dialog.style}Button" </button>', onClick: function() { var var1 = {dialog.Object}.getValueFrom(this); {dialog.Object}.setValue('textarea', var1)}, value: 'a'};
    				{html: 'B', value: 'B'},
    				{html: 'C', value: 'C'},
    				{html: 'D', value: 'D'},
    				{html: 'E', value: 'E'},
    				{html: 'F', value: 'F'},
    				{html: 'G', value: 'G'}
    				
    			]  
    
    	}
    ]
    Thank you for your help!

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,568

    Default Re: JSON onClick function to set a value into textarea

    Without looking at your code too much at this point I would suggest you call a javascript function from your onClick event instead of trying to embed all the code into your html.

    Putting what you need into a function will let you debug it easily as well.

    I'd also suggest you post a simple UX with the menu and this code implemented so we can have something to work with.

  3. #3
    Member
    Real Name
    M
    Join Date
    Oct 2012
    Posts
    115

    Default Re: JSON onClick function to set a value into textarea

    David,
    I think i figured that out, i used action JavaScript with Menu Builder instead of static JSON string . But now i am working to make my vertical drop down menu to horizontal menu.
    See this test3.zip
    Last edited by Ferenju; 06-24-2014 at 11:11 PM.

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,568

    Default Re: JSON onClick function to set a value into textarea

    This is your JSON...

    Code:
    [
    	
    	{
    		type: 'radio-group',
    		variable: 'radioGroup1',
    		columns: 7, //number of columns in which to display the data. If you leave this out, the data is displayed in a 'square'.
    		data: [
    				{html: '<button onClick=\'setMenuChoice("A");\'>A</button>', value: 'A'},
    				{html: '<button onClick=\'setMenuChoice("B");\'>B</button>', value: 'B'},
    				{html: '<button onClick=\'setMenuChoice("C");\'>C</button>', value: 'C'},
    				{html: '<button onClick=\'setMenuChoice("D");\'>D</button>', value: 'D'},
    				{html: '<button onClick=\'setMenuChoice("E");\'>E</button>', value: 'E'},
    				{html: '<button onClick=\'setMenuChoice("F");\'>F</button>', value: 'F'},
    				{html: '<button onClick=\'setMenuChoice("G");\'>G</button>', value: 'G'}
    			]  //data can can an array of JSON objects, or an array of strings (if the 'html' and 'value' are the same)
    
    	}
    ]
    And this is the Javascript function...

    Code:
    function setMenuChoice(menuSelection){
    
    	{dialog.Object}.setValue('chatwindow', menuSelection);
    
    }
    That's a clever use of the menu... thanks for that.

  5. #5
    Member
    Real Name
    M
    Join Date
    Oct 2012
    Posts
    115

    Default Re: JSON onClick function to set a value into textarea

    David,
    I changed the java script code to this , so that when you click a letter from the popup it will inserts the value one after another

    Code:
    function setMenuChoice(menuSelection){
    var var1 = {dialog.Object}.getValue('chatwindow')+ menuSelection;
    {dialog.Object}.setValue('chatwindow', var1);
    
    }
    and also I added a class for the BUTTON to have style , like this
    Code:
    {html: '<button class="{dialog.style}Button" onClick=\'setMenuChoice("A");\'>A</button>', value: 'A'},
    Thank you for you help.
    That was a very good team work.
    Last edited by Ferenju; 06-25-2014 at 12:39 AM.

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,568

    Default Re: JSON onClick function to set a value into textarea

    Yes... I forgot to say I left out the button class because I didn't have it... and I didn't want to complicate things until it was working.

    The example JSON for the menu has the menu in a vertical orientation... and with that... the example onclick code works by just using a setValue method... you don't need anything else.

    But... I could not get that code to work in a Horizontal menu orientation.

  7. #7
    Member
    Real Name
    M
    Join Date
    Oct 2012
    Posts
    115

    Default Re: JSON onClick function to set a value into textarea

    OK, every thing works except the onClick event on the popup letters doesn't trigger on mobile device, but it works on desktop browser.
    Do you have any clue how to fix that for touch device ?
    Last edited by Ferenju; 06-25-2014 at 10:14 PM.

  8. #8
    Member
    Real Name
    M
    Join Date
    Oct 2012
    Posts
    115

    Default Re: JSON onClick function to set a value into textarea

    I found a solution - I used
    ontouchstart="alert('button1')"

    and VOOLLAA works everywhere.
    Last edited by Ferenju; 06-26-2014 at 11:17 AM.

Similar Threads

  1. passing JSON from Xbasic function to javascript
    By lilmofo812 in forum Mobile & Browser Applications
    Replies: 7
    Last Post: 11-12-2014, 10:12 AM
  2. global function from onclick
    By son04littleelm in forum Mobile & Browser Applications
    Replies: 5
    Last Post: 10-21-2013, 04:37 PM
  3. grid - row onclick set value and then save
    By richard2007 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 6
    Last Post: 03-19-2013, 11:36 AM
  4. Can I Set the ONCLICK Event for the Grid in the Attached Image
    By Turnbullca in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 03-13-2013, 11:29 AM
  5. set value of a control with the onclick event
    By bob9145 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 04-16-2012, 09:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •