Jump to content

ajoo

Members
  • Posts

    871
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by ajoo

  1. Hi Guru Barand !

    Sir, You are correct but so am I because I said I want the derived table to be considered as the complete and only table itself thereby ignoring all the rows / values before the last 5 rows. 

    In which case this below is the only table. All other values are discarded and averages are calculated by taking RecNo 9 as the first record and so on. In that case  "your result" values would fit.

    +-------+----------+---------+----------+-------------------+-----------------+
    | recno | user     | v_score | reccount | last5             |  av5 = last5/5  |   my results      your results
    +-------+----------+---------+----------+-------------------+-----------------+
    |     9 | mina1111 |       4 |        5 | 2 + 4 + 3 + 2 + 4 | 15/5 = 3.0      |    3.0000            4.0000
    |    10 | mina1111 |       5 |        6 | 4 + 3 + 2 + 4 + 5 | 18/5 = 3.6      |    3.6000            4.5000
    |    11 | mina1111 |       0 |        7 | 3 + 2 + 4 + 5 + 0 | 14/5 = 2.8      |    2.8000            3.0000
    |    12 | mina1111 |       1 |        8 | 2 + 4 + 5 + 0 + 1 | 12/5 = 2.4      |    2.4000            2.5000
    |    13 | mina1111 |       1 |        9 | 4 + 5 + 0 + 1 + 1 | 11/5 = 2.2      |    2.2000            2.2000
    +-------+----------+---------+----------+-------------------+-----------------+
     
    

    Thank you sir !

  2. Hello Guru Barand !

    While the result table is great it does not produce the values I want.

    I wanted that this table be considered as the complete and only table for which the rolling averages needed to be found. So for  your result table the values that I was looking for in the av5 columns should be as below. (I have changed the av5 values that I am looking for)

     

    +-------+----------+---------+----------+--------+
    | recno | user     | v_score | reccount | av5    |
    +-------+----------+---------+----------+--------+
    |     9 | mina1111 |       4 |        5 | 4.0000 |
    |    10 | mina1111 |       5 |        6 | 4.5000 |
    |    11 | mina1111 |       0 |        7 | 3.0000 |
    |    12 | mina1111 |       1 |        8 | 2.5000 |
    |    13 | mina1111 |       1 |        9 | 2.2000 |
    +-------+----------+---------+----------+--------+

     

    The following query gives me the table I want but since it is a temp table, I am unable to open it again for creating the averages.

    create temporary table mina1111_a
     Select * from (
    	select a.RecNo
    	, a.User
    	, a.V_Score
    	from ajoo as a
    	where User = 'mina1111'
    	ORDER BY RecNo DESC LIMIT 5)sub
     Order by RecNo ASC;

    It gives on my table the following values:-

    +-------+--------------+------------+
    | RecNo | User         | V_Score    |
    +-------+--------------+------------+
    |    10 | mina1111     |          5 |
    |    11 | mina1111     |          0 |
    |    13 | mina1111     |          1 |
    |    14 | mina1111     |          1 |
    |    15 | mina1111     |          1 |
    +-------+--------------+------------+

    But I am unable to use the table to get the averages. It gives the can'r reopen table error.

    Thanks !

     

     

     

     

  3. Hi all !

    i have the following table in my DB

    Quote

    +----------+-------------------+-------------+-------------+
    | RecNo  |     User           | V_Score  | Average   |
    +----------+-------------------+-------------+-------------+
    |     1       |     tina1234     |    NULL    |    NULL   |
    |     2       |     dinesh11    |    NULL    |    NULL   |
    |     3       |     mina1111    |       2       |  2.0000    |
    |     4       |     nina12345  |       3       |  2.5000    |
    |     5       |     rina1234     |       4       |  3.0000    |
    |     6       |     mina1111    |       4       |  3.2500    |
    |     7       |     mina1111    |       3       |  3.2000    |
    |     8       |     mina1111    |       2       |  3.2000    |
    |     9       |     mina1111    |       4       |  3.4000    |
    |    10      |     mina1111    |       5       |  3.6000    |
    |    11      |     mina1111    |       0       |  2.8000    |
    |    13      |     mina1111    |       1       |  2.5000    |
    |    14      |     mina1111    |       1       |  1.7500    |
    |    15      |     mina1111    |       1       |  0.7500    |
    +----------+-------------------+-------------+-------------+
     

    The averages are the rolling averages for 5 records at a time. If I try and get the same for only the user mina1111 using the query

    SELECT user.RecNo as RecNo, user.User as User, user.V_Score as V_Score, avg(user_past.V_Score) as Average 
    FROM user  
    JOIN user as user_past on user_past.RecNo between user.RecNo-4 AND user.RecNo WHERE user.User = 'mina1111'
    GROUP by RecNo, V_Score;
    
    
    

    I get the following :-

    Quote

    +----------+----------------+---------------+---------------+
    | RecNo  | User            | V_Score    |     Average |
    +----------+----------------+---------------+---------------+
    |     3       | mina1111     |       2         |      2.0000   |
    |     6       | mina1111     |       4         |      3.2500   |
    |     7       | mina1111     |       3         |      3.2000   |
    |     8       | mina1111     |       2         |      3.2000   |
    |     9       | mina1111     |       4         |      3.4000   |
    |    10      | mina1111     |       5         |      3.6000   |
    |    11      | mina1111     |       0         |      2.8000   |
    |    13      | mina1111     |       1         |      2.5000   |
    |    14      | mina1111     |       1         |      1.7500   |
    |    15      | mina1111     |       1         |      0.7500   |
    +----------+-----------------+--------------+----------------+

    The averages go all haywire. It uses the values in the original table to calculate these, hence the funny values. So how can I get the correct values like this was the table with original values.

    Also how can I get the values of say only the last 5 values, considering those were the only values / rows in the table. i.e. the rolling avgs of 

     

    Quote

    +----------+----------------+---------------+---------------+
    | RecNo  | User            | V_Score    |     Average |
    +----------+----------------+---------------+---------------+
    |    10      | mina1111     |       5         |     5.0000   |
    |    11      | mina1111     |       0         |     2.5000   |
    |    13      | mina1111     |       1         |     2.0000   |
    |    14      | mina1111     |       1         |     1.7500   |
    |    15      | mina1111     |       1         |     1.6000   |
    +----------+-----------------+--------------+--------------+

    Thanks all !

     

     

  4. Hi all !

    is there a difference between an array of arrays as 

    rs1 = [
    	[1,5,6,7,8,9],
    	[ 2,7,6,5,4,3],
      	[3,12,13,14,15,16]
     ];

    and another formed as below as

    var rs1 = "1,5,6,7,8,9 2,7,6,5,4,3 3,12,13,14,15,16";
    rs1 = rs1.split(" ");
    
    //alert(rs1[0]);
    //alert(rs1[1]);
    //alert(rs1[2]);
    //alert(rs1.length);

    if so, can someone explain what the difference is.

    Thank you !

  5. Hi !

    I have a working fiddle here https://jsfiddle.net/zswrd5oh/

    While it works great for the 1st pass, (a table of 2 - 1st 9 even values )  the 2nd pass, though it works through it and gives the wanted result ( table of 3), is still flawed, in that it generated extra return key codes thereby upsetting the code logic and generating error conditions ( red boxes).

    I know its a bit difficult to explain but can easily be figured if the fiddle is run twice using the ready button. I have set alerts which are different in the 2 cases. Also if run in the browser, the console.log shows how the keys are registered by the program differently in the 2 passes. 

    Ideally it would be best if the 2nd pass runs just like the first pass did.

    Would be grateful for any help to resolve this. 

    Thanks !   

  6. Hi,

    @cyberRoot : Thanks for the response. Yes I am / was using the keypress event.  

    @Guru Barand: 

    My code at the juncture I put this question was as below:

    	
    // 	each input element has a unique id = 'result_1', 'result_2' and so on.
    		m=1;		
    		myResult = $('#result_'+m);
    
    		ansUp = ['5','11','18','26'...];
    		
    		$('input[type=text]').prop("disabled", true);
    //		console.log(myResult);		
    		myResult.prop('disabled',false);
    		myResult.val(0);
    		myResult.select();
    		myResult.addClass('yellow');	
    
    	while(m < 9){
    		
    		myResult.keypress(function(e) {
    			if (e.keyCode === 13) {
    				myval = myResult.val(); 
    				if(myval == ansUp[m-1])
    				{
    					myResult.addClass('green');
    					myResult.prop('disabled',true);
    					m++;
    					myResult = $('#result_'+m);
    					myResult.prop('disabled',false);
    					myResult.addClass('yellow');					
    					myResult.val(0);
    					myResult.select();
    					return true;
    				}
    				else {
    					myResult.addClass('red');
    					myResult.select();
    					return false;
    				}	
    			}	
    		})
    
    	}	

    I thought the while loop would work but then obviously that was incorrect. So i removed the while loop and thought I should add 

    myResult.keypress(function(e) {.... }  // just before return true.

    but that made it cyclic and that too was not great. I was missing the idea of a common class changing event which you were kind enough to show me in your code. 

    Now I have it working for the most, the only issue is that the enter key needs to be pressed twice before the event is registered which is very odd.  Here is the final code which needs me to press the enter key twice.  I suspect it has something to do with the '0' value that I put into the input box and then put the focus on that for the ease of the user. 

    Here's how it stands now:

    	$(".ui").change(function(){
    		myResult.keypress(function(e) {
    			if (e.keyCode === 13) {
    				myval = myResult.val(); 
    		
    				if(myval == ansUp[m-1])
    				{
    					if(myResult.hasClass('red')){
    						myResult.removeClass('red');
    					}
    					myResult.addClass('green');
    					myResult.prop('disabled',true);
    					m++;
    					myResult = $('#result_'+m);
    					myResult.prop('disabled',false);
    					myResult.addClass('yellow');					
    					myResult.val(0);
    					myResult.select();
    				}
    				else {
    					myResult.addClass('red');
    					myResult.select();
    				}	
    			}	
    		})
    	})	

    Please help !

    Thanks loads Guru Barand and cyberRoot !

  7. Hi, 

    I need to collect user inputs in input boxes. All boxes are disabled except the one which awaits input. once an input is made and satisfies a certain criteria, the next input box in the sequence is enabled and awaits input. 

    Thus i need my code to cycle a certain section of my code and collect all inputs which is like saying it needs to do nothing as it waits for the user input. I cannot put this in any loop because it freezes the loop. The only way I can think of accomplishing this is by using a setTimeout and awaiting for keypress during that time, collecting input, breaking out of the loop, and targetting the next inputbox in the setTimeout function till all input is collected. I just wish to know if anyone has a better idea to do this task.

    Thanks !

  8. Hi ! 

    @cyberRoot: Thanks for the additional information. I am aware that it's not supported by IE but it seems to work fine in chrome. I have never used let in for loops earlier so I simply removed the let and it works fine anyways. 

    I have read the links you have provided and it seems that there is no advantage of using it except for the fact that it may be a bit faster since it is bound only once for all iterations. I'll look up google analytics, though i have not ever used it.

    Thanks !

     @Maxxd : Thanks for the reply. I think all experts in the forum and really very helpful and nice without exceptions. I'll do try out things in quite detail actually before I ask. I'll keep in mind your advice. Thank you again !

     

  9. Hi !

    @cyberRoot Thank you for that insight. Yes I am trying to avoid any inline code. After what you have pointed out, I think I will have to scrutinize my existing code as well.

    I think Guru Barand has implemented the addclass mechanism, you suggested in your reply already.

    @maxxd Thanks for replying to so many of my doubts. 

    Quote

    Could I have done it using say the class property or the name of the input field instead of using tabIndex?

    Quote

    if so, then can you kindly demonstrate how it could be done by that method. 

    To both of the above, I was actually referring to this bit of code below

    $("input[tabindex = "+ind+"]")

    where I was wondering if the same functionality could be achieved using name or .class in place of tabindex. Even though it works it does seem rather ugly to use like this. ( tabindex needed to be defined before it was used. I know that the for such array of elements, the name property gets assigned an array with an inherent index value) .

    Quote

    Admittedly, I'm asking you to think a little when it comes to some of it, but ... really? Beyond that, Barand has been his typical self and gone above and beyond the call of duty to answer your questions in no uncertain terms and with concrete code examples; yet there are more requests to simply do it for you.

    Only for the sake of clarification, It's because I am thinking and trying things out that I get all these questions in my head and I do like to clarify as far as possible. I do not come back with my doubts unless I have tried out things further, read and searched the net and tried to find my answers. For eg. In my last reply, I found a method to target the individual cell but came back to clarify if it was the correct method and to learn if it could be done using the name property etc. So it's not like I am asking to do it but a bit of code definitely helps clarify a lot.

    Thank you for the fiddle on grids. I'll study it and maybe change to do eventually like that. I do have more questions, but seriously, I am a bit scared to ask them. 

    Yes Guru Barand is has, as always, been most helpful and generous too !

    @ Guru Barand : I can't thank you enough for all your help and all that I have learnt from you. 

    No offence to anyone  please. I can only be grateful for all the help and assistance that I have received at the forum for years !  Thank you all !🙏

     

     

     

     

  10. hi Guru Barand,

    This is how I finally managed to do it using css

    $( document ).ready(function(){
        ccmatrix = $("#ccMatrix");
        var form = $("<form/>", {action: '#',method: '#'}); 
        counter = 0;        
            for(i=0; i<3; i++)
            {
                for(j=0; j<3; j++)
                {    
                    ind = j*3+i;      
                    if(ind<3) clr = '#ff11aa';
                    if(ind>=3 && ind<6) clr = '#aaff11';
                    if(ind>=6 && ind<=9) clr = '#11aaff';
      
                    $(ccmatrix).append($("<input/>", {
                        type: 'text',
                        class: 'result',
                        name: 'u_i',
                        size: '1px',
                        tabindex: j*3+i,
                        value: j*3+i
                        }));
    
                    $("input[tabindex = "+ind+"]").css('backgroundColor', clr);    
                }
                $(ccmatrix).append('<br>');          
              }        
    });

    using the tabindex property of the input to target a specific input element in the matrix using 

    $("input[tabindex = "+ind+"]").css('backgroundColor', clr);

    I hope this is the right way to go about it. If there is a better simpler way, please suggest. Could I have done it using say the class property or the name of the input field instead of using tabIndex? If so, then can you kindly demonstrate how it could be done by that method. 

    Thank you !!

     

     

  11. Hi, 

    I'll try out things and revert. I created my string of params ( commented in my fiddle ) separated by  ',' and space but did not try it with the semi colon.🤔

    I do have a question though, by using styles like this would I be upsetting the CSP Policy ? Would this be considered as inline ? In which case it could be a problem since I have kept all my code thus far to be CSV compliant. 

    Thanks loads Guru Barand ! 🙏

  12. Thank you Guru Barand !

    May I ask if and how can we set more than one style property in the style attribute passed to input

    style: 'background-color:'+clr

    I tried to add change some more styles but either it's not permissible, though i doubt that, or constructing comma separated key : value pairs is not permitted. Please show the correct syntax if that can be achieved. 

    What other key value can be set in the Input dynamically? Like i said earlier, I could not find any tutorial or example demonstrating other such changes. 

    Finally one last thing, how can I set focus to any one particular box, say the middle one ( 5th one )?

    Thanks loads !

  13. Hi 

    @Guru Barand : I have modified the jsfiddle slightly and I want to get the bottom two blocks to somehow be placed next to the first red block.

    https://jsfiddle.net/Lk5fzwbu/

    The values inside the boxes are not the inputs but simply a way for me to identify them. This way the tab key moves the cursur down the column of fields as I would want it to move, i.e. downwards and not sideways, I tried to create a param ( commented out in the fiddle ) string to provide for more styles and replace the single background style but it did not work and also, surprisingly, did not give any error as well. The idea was to change the top and left absolute position of the 3rd and 6th box to place them by the side of the first block. The lower boxes would be placed relatively correctly I suppose like in the first block. It did not work at all. 😰

    I could not find a single example which shows the usage / correct syntax of style inside the append method. 

    Please suggest. 

    Thanks loads !

     

  14. Hi all !

    Thank you for all the inputs. That's a lot of information to digest early morning !!😄 

    @ cyberRoot : The values are not available upfront, hence the input fields are used for the grid. But thank you very much for the idea. 

    @,maxxd: I'll check out the grid. I have read about it but thought this should be simple enuff to do using css and positioning. Thank you. 

    @Guru Barand:  Sir, it took me  a long time to figure this out when i couldn't get to position the blocks correctly and the values in loops made no sense at all. That's when I tried to color the boxes to see what was going on and finally after hours realized that the changes were cascaded to all the previous input elements formed as well. 

    Thanks !

  15. Hi all !

    I  am trying to make a 3 by 3 grid of input fields inside a form using. I have created a fiddle here https://jsfiddle.net/68pgk2d4/

    It simply creates a column of 9 input fields. What I want to do is to place them as below.

    1 -- 4 -- 7 

    2 -- 5 -- 8

    3 -- 6 -- 9

    If I try and manipulate the css properties of the fields after they have created ( as an eg I have changed the color property ), it affects all the fields created till that stage and not just the newly created field. ( un-commenting  i=1, will change the color of all the fields to that color. The magenta color of the 1,2,3 fields also gets changed).  I would like to know if there is a way to get a handle on each of the cells so as to target them specifically.

    Please can someone help me accomplish this. 

    Thanks !

     

     

  16. Hi Requinix, 

    Thanks for the clarifications. Of-course you are correct. 

    Quote

    Do you know what /.../g does?

    No I did not but I found out, it performs a global  search across the test string. 

    yes so I reverted my code to exactly as pointed by Guru Barand. That was the correct code. I was getting the error because i was using it on the regex instead of the string. 

    Thanks again !

     

  17. HI, 

    Thank you all !

    @daveyerwin :  While most examples use the "/ .... /g" pattern, it seems not to work.  Even I was misled by this. 😥

    @Guru Barand:   Thank you, it works ! 🙏😃

    @ requinix: I initially used the /^... $/ but was getting an error & since all examples I saw used the /... /g, I switched. The .test() should be .match(). If I use .test(), i get a " is not a function" error ! .match() works fine. If there is something more esoteric here that I am missing please say.

    The final working code block :  

    		sw_ui = $(".sw_ui").val();	
    		alert(sw_ui);
    		pattern = /^\d+$/;
    		isnum = sw_ui.match(pattern);
    		alert(isnum);

    Thanks loads !!

     

     

     

  18. hi,

    The following bit of code tries to enforce an all digits, with a maxlength of 6, input from the user.   The first alert shows the digit correctly while the second alert(check) always gives null.  

    HTML:			
    		.
    		.
    		<input type="text" class="sw_ui" name="sw_ui" value="0" maxlength="6" />
    		.
    		
    
    JS:
    		test = $(".test").val();	
    		alert(test);
    		pattern = /[0-9]{6}/g;
    		check = test.match(pattern);
    		alert(check);

    Can someone please tell me why? What's the mistake here since I should be getting a match. 

    Thanks !

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.