0

I finished all my psets, and was working on trying to implement some javascript in with the PHP forms we built in pset7. It seems that by building the template and the view based upon the CS50 implementation of MVC, you can't use jQuery to modify the form in real time. Either the call to render() or the callback to another page is screwing this up.

For example, with the below script, I can change the border of a field to become red if the user clicks in the field but enters nothing & goes to another field...but only if the form is built on one page (no rendering of a separate header & footer like we did in CS50 Finance).

$('#contact_name').on('input', function() {
var input=$(this);
var is_name=input.val();
if(is_name){input.removeClass("invalid").addClass("valid");}
else{input.removeClass("valid").addClass("invalid");}
});

It is saved in a scripts.js file which I tried referencing in the header, body, and footer.

1
  • Lots of info, but what is your question? Please edit the question to actually add your question. thanks.
    – Cliff B
    Nov 11, 2015 at 6:45

1 Answer 1

0

I struggled with this for several hours per day for over a week, but I figured it out. First problem was a bad path to the scripts.js file. Then I found if I added the script tags as the first lines of the body template that is rendered (not in the header.php or footer.php templates) the script will run. Amazing how simple stuff can be overlooked sometimes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .