jeudi 3 septembre 2020

Updating input, to update variable, to update table

I am trying to create a simple table where you enter a registration number, and then the car name is put in to the cell adjacent to it.

I am using variables and when writing the if statement, it goes either one of two ways despite the conditions.

Below is the code for the if statement:

$("input[type='text']").change(function(){
$(this).closest('td').text($(this).val())});

var car1 = "Little White";
var car_1_reg = "NP60UQQ";

var car_reg_1 = $("#car-1-reg").html();
var car_name_1 = $("#car-1-name").html();
$(".confirm").click(function() {
if (car_reg_1 != car_1_reg) {
    car_name_1.innerText = 'Not a valid Registration';
}   else {
    car_name_1.textContent = car1;
}});

and I have uploaded the full project to jsfiddle here: https://jsfiddle.net/Coxy/pyho3as2/1/

I have spent most of the day trying to get the first part to work, once I have that right I can apply the logic across to the other parts (enter miles left and update miles till charge etc.

Any pointers would be really appreciated.

Aucun commentaire:

Enregistrer un commentaire