Tuesday, March 15, 2011

javascript attributes

I was trying to find a way to make an image grow big and then small each time you click on it. I used these functions

function open_enlarge(plan){
$('#'+plan).addClass('largemap');
$('#'+plan).removeClass('smallmap');
document.getElementById(plan).setAttribute('onclick', 'close_enlarge("'+plan+'");');
$('#addjob_floorplan').attr('onclick', 'close_enlarge("addjob_floorplan")');
}

function close_enlarge(plan){
$('#'+plan).removeClass('largemap');
$('#'+plan).addClass('smallmap');
document.getElementById(plan).setAttribute('onclick', 'open_enlarge("'+plan+'");');
$('#addjob_floorplan').attr('onclick', 'open_enlarge("addjob_floorplan")');
}

Then it didn't work in internet explorer so I decided to go with a simpler way with jQuery with only 1 function call toggling 2 classes back and forth instead of having to change the onclick event and having to make it different for Internet explorer 7:

function open_enlarge(plan){
$('#'+plan).toggleClass('largemap','smallmap')
}

Test case Idea for php, javascript and mysql

I want to make some kind of test case for my websites

It automatically runs a script to recreate the test database each time abd then run the same javascript commands that a user would run normally.

The script would pretend to be a user and then analyze the finished data and expect the same result every time and if its different then it will report an error with details after the test. It will log errors during the test as well. It could be logged on a file or emailed or in a database you can look at from in the admin of the website and have the test done everyday or manually started.
My sites usually have alot that goes on and if there was something to run that tests everything or at least the hardest problems to catch then it would be worth the effort
especially when the changes I make can break something only the customers would see.