10 Replies - 704 Views - Last Post: 19 May 2016 - 10:36 AM

#1 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Beginner with a few questions

Posted 17 May 2016 - 02:41 PM

So at work I am being trained in Javascript by being thrown an already live application and adding very small changes to it, but with Javascript I really just have a basic 101 level of understanding. So I have to learn certain things on the fly.

So my first question:

I have this function:
function alert_BindFilterNEvents (id, index)
Yet the parameters are not set anywhere in the .js page. There is a .css page and .php page, and I don't see anywhere in those pages where those parameters are set. So is there anyone who could perhaps give me hints on where I could typically find where a parameter is if it is not set in a .js page? This may be to general of a question to answer, if so let me know other details that would help you help me.


2nd question:

Since I have little experience in PHP, Javascript and CSS, can anyone lead me to a good tutorial that shows how they work together?

3rd question:

If someone gave you a page of code that you had no idea what it is in fact doing, how would you best disseminate the code to learn what it is doing? Pretend that you don't know JS or PHP....

I don't have any deadline or time frame so I could take a bit of time figuring this out, but I don't want to spend a lot of time educating myself with bad information or going in the wrong direction, as I want to head in the right direction.

Thanks advance for your help and apologies if this is a very general question. And I am posting this as I leave work so I won't be able to respond to any questions until tomorrow. But I will gladly read anything reference wise that pertains to this.

This post has been edited by jphoc13: 17 May 2016 - 02:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Beginner with a few questions

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1789
  • View blog
  • Posts: 5,702
  • Joined: 15-January 14

Re: Beginner with a few questions

Posted 17 May 2016 - 02:49 PM

Search for the name of that function in all of the files to see where it's used. The values would be passed when the function gets called. In Javascript it's not a requirement to pass parameters though, the function might also check if those values are undefined and use default values in that case.

Quote

Since I have little experience in PHP, Javascript and CSS, can anyone lead me to a good tutorial that shows how they work together?

I don't know of a particular tutorial (although if you look for books you'll find quite a few), but in general PHP is executed by the web server, and Javascript is executed by the user's browser. They do not directly interact with each other. You can use PHP to write anything (including Javascript code) that you want the web server to send to the browser, though. And you can also use Javascript to send requests to the web server and get a response back. In general, PHP is used for things that happen on the server, like interacting with a database or sending emails, and Javascript is used for things that happen in a browser, like clicking on a button or controlling a slideshow or whatever. CSS is just used for adding style to pages.

Quote

If someone gave you a page of code that you had no idea what it is in fact doing, how would you best disseminate the code to learn what it is doing? Pretend that you don't know JS or PHP....

If you don't know the language you aren't going to be able to understand it. It's like giving an American a page written in Russian and expecting them to understand it without learning Russian.
Was This Post Helpful? 1
  • +
  • -

#3 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Re: Beginner with a few questions

Posted 18 May 2016 - 05:57 AM

Yeah I do know what the languages are doing(JS and CSS), I just don't know PHP at all. But your middle paragraph explained what I was looking for in regards to what PHP does. Thanks!

This post has been edited by jphoc13: 18 May 2016 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Re: Beginner with a few questions

Posted 18 May 2016 - 08:17 AM

Ok so I think I have a good general idea of what I need to do. My task is quite simple for an experienced programmer but difficult for me.

I have two Div sections:

var vTrigger = document.getElementById('divAlertTrig');
    var vReset = document.getElementById('divAlertReset');


Each one of these div sections has 3 other divs:

var bIsSection1Enabled = $('#' + id + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enable');
    var bIsSection2Enabled = $('#' + id + "_NSection2").hasClass('txAlert_GridFilterN_Section_Enable');
    var bIsSection3Enabled = $('#' + id + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enable');


Right now the program will fill the div section with id
txAlert_GridFilterN_Section_Enable
as blue.

What I want to do is if both div sections

var vTrigger = document.getElementById('divAlertTrig');
    var vReset = document.getElementById('divAlertReset');


that show this var as true or enabled:

bIsSection1Enabled

Then I need to color the div section with id:

'txAlert_GridFilterN_Section_Enable'

as red, to indicate a MisMatch.

My thought process is that I should create a function:
function alert_MisMatch(id)

That handles that.

so I have two questions:

1) Am I on the right track logically?
2) Can anyone perhaps point me to a tutorial or other example that does something similar to what I am trying to accomplish?

This post has been edited by jphoc13: 18 May 2016 - 08:28 AM

Was This Post Helpful? 0
  • +
  • -

#5 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Re: Beginner with a few questions

Posted 18 May 2016 - 09:23 AM

This is where I am at right now. Hoping this is going in the direction I was indicating above, and people get a better understanding of what I am trying to accomplish.

function alert_MisMatch(id) {
    var vTrigger = document.getElementById('divAlertTrig');
    var vReset = document.getElementById('divAlertReset');
    
    
    var bIsSection1Enabled = $('#' + id + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enabled');
    var bIsSection2Enabled = $('#' + id + "_NSection2").hasClass('txAlert_GridFilterN_Section_Enabled');
    var bIsSection3Enabled = $('#' + id + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enabled');
    if((vTrigger & bIsSection1Enabled) & (vReset & bIsSection1Enabled))
    {
        //Do Stuff
        bIsSection1Enabled = $('#' + id + "_NSection1").hasClass('txAlert_GridFilterN_Section_MisMatch');
    }

}


CSS:

.txAlert_GridFilterN_Section_MisMatch 
{
    position: relative;
    top: 10px;
    
    width:50px; 
    height: 20px; 
    background-color: red; 
    float: left;
    border: 1px solid gray;
}


I know this likely won't work, but would like to be advised on what I am doing wrong, what I am missing, etc....

This post has been edited by jphoc13: 18 May 2016 - 10:10 AM

Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1789
  • View blog
  • Posts: 5,702
  • Joined: 15-January 14

Re: Beginner with a few questions

Posted 18 May 2016 - 10:26 AM

Use && for logical and, using & is a bitwise and.

This line:

bIsSection1Enabled = $('#' + id + "_NSection1").hasClass('txAlert_GridFilterN_Section_MisMatch');

is checking if the element currently has that class on it. If you want to add the class to the element I think you use addClass.
Was This Post Helpful? 1
  • +
  • -

#7 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Re: Beginner with a few questions

Posted 18 May 2016 - 12:40 PM

Ok I think I figured out WHAT I need to do, I just don't know HOW to do it.

In my php page I have these JS function calls:

alert_BindFilterNEvents('txAlertTrig', '1');
			alert_BindFilterNEvents('txAlertTrig', '2');
			alert_BindFilterNEvents('txAlertTrig', '3');
			
			alert_BindFilterNEvents('txAlertReset', '1');
			alert_BindFilterNEvents('txAlertReset', '2');
			alert_BindFilterNEvents('txAlertReset', '3');


Basically I need to find a way to create an alert in JS when both of the below events are bound.

alert_BindFilterNEvents('txAlertReset', '1');
alert_BindFilterNEvents('txAlertTrig', '1');



Here is the Bind function in JS:

function alert_BindFilterNEvents (id, index) {
    console.log('bind ...');

    var sControlID = id + "_NSection" + index;
    $('#' + sControlID).bind('click', function(evt) {
        var sSectionID = id + "_NSection" + index;
        $('#' + sSectionID).toggleClass("txAlert_GridFilterN_Section_Enable");
        $('#' + sSectionID).toggleClass("txAlert_GridFilterN_Section_Disable");

        console.log('clicked ' + sSectionID);
        alert_CheckEnableInput(id);
    });
};


I admit I don't know entirely what is going on in the above function, and I don't want to do a massive code drop and drop all the code on the JS page I am learning.

But I do know that I need to find a way to create an alert_function, when the two functions I posted above are bound. I would imagine I have to find a way to store somewhere that two functions are bound, but really have no idea how to do that.
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1789
  • View blog
  • Posts: 5,702
  • Joined: 15-January 14

Re: Beginner with a few questions

Posted 18 May 2016 - 04:14 PM

Quote

Basically I need to find a way to create an alert in JS when both of the below events are bound.

I'm not sure what the purpose is, why not just call another function after binding the 2 events?
Was This Post Helpful? 1
  • +
  • -

#9 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Re: Beginner with a few questions

Posted 19 May 2016 - 06:08 AM

Ok so my trainer told me I needed to add the code into this function that handles the event.

Would something like this if statement (the second one) ever trigger if two events occur?

function alert_CheckEnableInput(id) {
    var bIsReset = false;
    if (id.indexOf('Reset') > 0) {
        bIsReset = true;
    }
    
    var bIsSection1Enabled = $('#' + id + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enable');
    var bIsSection2Enabled = $('#' + id + "_NSection2").hasClass('txAlert_GridFilterN_Section_Enable');
    var bIsSection3Enabled = $('#' + id + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enable');

 if ((bIsReset && bIsSection1Enabled) && (!bIsReset && bIsSection1Enabled))
    {
        alert_MisMatch('txAlertReset', '1');
    }
}


This post has been edited by jphoc13: 19 May 2016 - 07:35 AM

Was This Post Helpful? 0
  • +
  • -

#10 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1789
  • View blog
  • Posts: 5,702
  • Joined: 15-January 14

Re: Beginner with a few questions

Posted 19 May 2016 - 10:35 AM

That if statement will never be true because you're telling it to only run if bISRest is true and also if bIsReset is false. It's never going to be both true and false.
Was This Post Helpful? 0
  • +
  • -

#11 jphoc13  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 579
  • Joined: 08-July 13

Re: Beginner with a few questions

Posted 19 May 2016 - 10:36 AM

Yep, you're right. But since I posted that I actually have it working now with some minor bugs.

 if ($('#' + "txAlertTrig" + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enable')  &&
        $('#' + "txAlertReset" + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enable'))
    {
        $('#' + "txAlertReset" + "_NSection1").toggleClass('txAlert_GridFilterN_Section_MisMatch');
    }
    if ($('#' + "txAlertTrig" + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enable') &&
        $('#' + "txAlertReset" + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enable')) {
        $('#' + "txAlertReset" + "_NSection3").toggleClass('txAlert_GridFilterN_Section_MisMatch');
    }
    if ($('#' + "txAlertTrig" + "_NSection2").hasClass('txAlert_GridFilterN_Section_Enable') &&
        $('#' + "txAlertReset" + "_NSection2").hasClass('txAlert_GridFilterN_Section_Enable')) {
        $('#' + "txAlertReset" + "_NSection2").toggleClass('txAlert_GridFilterN_Section_MisMatch');
    }
    if ($('#' + "txAlertTrig" + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enable') &&
        $('#' + "txAlertTrig" + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enable') &&
        $('#' + "txAlertReset" + "_NSection1").hasClass('txAlert_GridFilterN_Section_Enable') &&
        $('#' + "txAlertReset" + "_NSection3").hasClass('txAlert_GridFilterN_Section_Enable')) {
        $('#' + "txAlertReset" + "_NSection1").toggleClass('txAlert_GridFilterN_Section_MisMatch');
        $('#' + "txAlertReset" + "_NSection3").toggleClass('txAlert_GridFilterN_Section_MisMatch');
    }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1