-1

So i have a jQuery script that i should explain it line by line, i already do that and i want to make sure that is correct, so this is my script :

 //Here we use the jQuery selector ($) to select the servers_id which is located into  
//the delivers_id and we attaches a function to run when a change event occurs

 $("#delivers #servers").change(function(){

//Here we look if the servers_id value was changed and the value is different of 0

    if($(this).val() != '0') {

//Here we create a new variable sid and we stored the servers_id value in it
        var sid = $("#delivers #servers").val();

//Here we use the Ajax $.get to get the sid value and send it by Ajax request then 
//we set the data into the o_vmats_id html and empty the vmtas_id
        $.get("/deliverability/get_vmtas/" + sid,
        function(data) { $('#o_vmtas').html(data); $('#vmtas').html(''); });
    } 

//Here the else statement, we select the vmtas_id and set the html content like in the code (value=0)
//and empty the o_vmtas_id html content
    else { $('#vmtas').html('<option value="0">All Classes</option>');  

     $('#o_vmtas').html(''); }
});

so please if someone has any remark i will be very appreciative

1
  • Ids must be unique, therefore you can just call $("#servers"), otherwise make each element's id unique or consider using classes. Commented Mar 5, 2014 at 12:10

1 Answer 1

0

You're looking for the #servers element twice, no need for that. You can and should cache items that are going to be looked up more than once, so store that element in a var at the very beginning.

Other than that... there's not much to it, other than you wouldn't actually need much jQuery to do this :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thnx Ricardo yes i know that, but actually it is not my script i just explain what is going on,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.