Excellent explanation of how to submit a form with ajax using jquery - visit :
http://www.ajaxlines.com/ajax/stuff/article/how_to_submit_a_form_with_ajax_in_jquery.php
Thursday, August 5, 2010
jQuery: Access value of selected/checked radio button
if you have a group of radio buttons (grouping done using same value for name attribute in all) and you want to get value of selected radio button out of them,
using jquery you can do that with below code snippet:
Suppose you have:
Diya [name="bolly",value="diya"]
Kareena [name="bolly",value="kareena"]
Katrina [name="bolly",value="katrina"]
Then,
You will get: sel_val = "diya"
For more reference:
http://stackoverflow.com/questions/986120/how-to-get-select-radiobutton-value-using-its-name-in-jquery
using jquery you can do that with below code snippet:
Suppose you have:
Diya [name="bolly",value="diya"]
Kareena [name="bolly",value="kareena"]
Katrina [name="bolly",value="katrina"]
Then,
var sel_val = $('input:radio[name=bolly]:checked').val();
You will get: sel_val = "diya"
For more reference:
http://stackoverflow.com/questions/986120/how-to-get-select-radiobutton-value-using-its-name-in-jquery
Monday, June 28, 2010
Javascript: Inline javascript function in event handler declaration
If you want to write javascript function code directly in the onclick event handler declaration instead of using a separate function for that code, you can do it as follows:
<input type="button" value="Save" onclick="javascript:(function(){ //your code; })();"/>
Monday, May 31, 2010
Google Maps: Best Fit Zoom Level and Center Point.
If you are working with Google maps and have an array of latitude longitude points to plot as markers on map, then you might need to calculate the best fit zoom level and map center point so that all the lat lng points can accommodate comfortably. Here's the code snippet:
For further reference:
http://911-need-code-help.blogspot.com/2009/03/zoom-to-fit-all-markers-polylines-or.html
// map: an instance of GMap2
// latlng: an array of instances of GLatLng
var latlngbounds = new GLatLngBounds();
for (var i = 0; i < latlng.length; i++)
{
latlngbounds.extend(latlng[i]);
}
map.setCenter(latlngbounds.getCenter(),map.getBoundsZoomLevel(latlngbounds));
For further reference:
http://911-need-code-help.blogspot.com/2009/03/zoom-to-fit-all-markers-polylines-or.html
Monday, May 17, 2010
Thursday, April 29, 2010
PHP: Get Yesterday's Date
echo date("Y-m-d", strtotime("-1 day") );
For some specific date:
echo date("Y-m-d", strtotime("2010-Jan-1 -1 day") );
Play around with this function to get your desired results. The PHP date parser is very smart.
Labels:
PHP
Tuesday, April 27, 2010
MySQL/SQL: 'ON DUPLICATE KEY UPDATE' for multiple rows insert in single query
Hello All.
I had a sql query where I wanted to insert multiple rows in single query. so I used something like:
$sql = "INSERT INTO beautiful (name, age)
VALUES
('Helen', 24),
('Katrina', 21),
('Samia', 22),
('Hui Ling', 25),
('Yumie', 29)";
mysql_query( $sql, $conn );
The problem was when I executed this query, I wanted to check whether a UNIQUE key (which is not the PRIMARY KEY), for eg. 'name' in above case, should be checked and if such a 'name' already exists, the corresponding whole row should be updated otherwise inserted.
For instance, in below eg., if 'Katrina' is already present in database, the whole row, irrespective of number of fields, should be updated. Again if 'Samia' is not present, the row should be inserted.
I thought of using:
Here is the trap. I got stuck and confused how to proceed. I had multiple rows to insert/update at a time. Then StackOverflow came to my rescue. Thanks to Peter Lang.INSERT INTO beautiful (name, age)
VALUES
('Helen', 24),
('Katrina', 21),
('Samia', 22),
('Hui Ling', 25),
('Yumie', 29) ON DUPLICATE KEY UPDATE
The Solution:
INSERT INTO beautiful (name, age)
VALUES
('Helen', 24),
('Katrina', 21),
('Samia', 22),
('Hui Ling', 25),
('Yumie', 29)
ON DUPLICATE KEY UPDATE
age = VALUES(age),
...
Subscribe to:
Posts (Atom)