Auto-running Javascript when edit.php window pops up?

Permalink
Howdy,

I am looking to run some javascript in a custom block when its edit.php window pops up. Basically I'd like to do something similar to an onload() event for the window.

The user's data added during add.php is saved properly to the db, and displays properly in view.php, but when edit.php runs I need to grab the data from the db and populate some fields in that window. This will allow the user to see what they have added and remove it if needed before updating.

I've considered just writing the fields in html and populating them with php, but this would result in me having to deal with both javascript and php versions (add.php being js, and edit.php being php). Btw, even if I do the php version, I would still need to use javascript for further dynamic node creation...

Any thoughts?

-Landson

Landson
 
aghouseh replied on at Permalink Reply
aghouseh
Should be able to just have a file named 'auto.js' next to the block's edit.php file and it will pick it up.
Landson replied on at Permalink Reply
Landson
My apologies, I shouldn't have put "Auto" in my title. My javascript loads fine, but I need a way to have one of my functions auto-run when the edit.php window pops up. I'm not sure just how to go about such a thing.

If the onload() event would work on a div, I'd just do that and pass my function the values I need to, e.g.

<div onload="myFunction(<?php echo $myArrayOfValues; ?>);"></div>


sadly onload() doesn't work like that. Perhaps there's a standard C5 way of doing this sort of thing?
aghouseh replied on at Permalink Best Answer Reply
aghouseh
Ah, yes. Time to get familiar with jQuery, my friend!

$(function(){ // this is a shortcut for when the dom is ready.
//your code here
});
Landson replied on at Permalink Reply
Landson
Thank'ee kindly, I'll start diggin' into it!
warhorse replied on at Permalink Reply
warhorse
Thank you, I was looking for an answer on how to do this too.