A Javascript Snippet
Posted: Sun Dec 02, 2007 4:27 pm
Well, not really 'javascript' but jQuery. You can find out more about jQuery at http://jQuery.com
Anyway, I get tired of typing the same crap over and over so sometimes I use JS to grab stuff from my html page and spit it out into the page in a way that I can use. Tonight I was grabbing POST info via php for a form. I made this little snippet to write out all of my input IDs surrounded by the stuff I needed to just paste it into the php code.
this output this into a the div#info:
modifying the string output a little bit and I got myself everything I needed for MySQL posting.
which output:
prepend that with an INSERT statement and off you go. Same goes for the VALUES line and pretty much anything else you may want to do some basic string manipulation with. Modify at will. It took me longer to write this post than it did to make the jQuery statement and get it into my PHP file!
Will
Anyway, I get tired of typing the same crap over and over so sometimes I use JS to grab stuff from my html page and spit it out into the page in a way that I can use. Tonight I was grabbing POST info via php for a form. I made this little snippet to write out all of my input IDs surrounded by the stuff I needed to just paste it into the php code.
- Code: Select all
$("form input, form textarea").each(function(){
var theID = $(this).attr("id")
$("#info").append('$' + theID + ' = $_POST["' + theID + '"];<br />');
});
this output this into a the div#info:
- Code: Select all
$zip = $_POST["zip"];
$title = $_POST["title"];
$time = $_POST["time"];
$address1 = $_POST["address1"];
$geotag = $_POST["geotag"];
$photograph = $_POST["photograph"];
$equipment = $_POST["equipment"];
$tags = $_POST["tags"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$url = $_POST["url"];
$description = $_POST["description"];
modifying the string output a little bit and I got myself everything I needed for MySQL posting.
- Code: Select all
$("form input, form textarea").each(function(){
var theID = $(this).attr("id")
$("#info").append(theID + ', ');
});
which output:
- Code: Select all
zip, title, time, address1, geotag, photograph, equipment, tags, fname, lname, email, url, description,
prepend that with an INSERT statement and off you go. Same goes for the VALUES line and pretty much anything else you may want to do some basic string manipulation with. Modify at will. It took me longer to write this post than it did to make the jQuery statement and get it into my PHP file!
Will