JavaScript - Calculate Age From Date Of Birth And Populate
Hi All,
My first question on this forum. I have a form where we are capturing the Members Children information. I want to insert age in years to a field within this table by calculating age from Date of Birth (DOB). DOB format is mm/dd/yyyy and is a datetime data type in SQL. The DOB is added by the member while registering their child. Is there an onchange script that I could use here. Is it possible to auto populate a field from an other field within the same form?? Does anyone have any code samples that I could use?? Any pointers will be greatly appreciated. Thanks Vinny Similar TutorialsCode: <script type="text/javascript"> /*********************************************** * Drop Down Date select script- by JavaScriptKit.com * This notice MUST stay intact for use * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more ***********************************************/ var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec']; function populatedropdown(dayfield, monthfield, yearfield){ var today=new Date() var dayfield=document.getElementById(dayfield) var monthfield=document.getElementById(monthfield) var yearfield=document.getElementById(yearfield) for (var i=0; i<31; i++) dayfield.options[i]=new Option(i, i+1) dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day for (var m=0; m<12; m++) monthfield.options[m]=new Option(monthtext[m], monthtext[m]) monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month var thisyear=today.getFullYear() for (var y=0; y<20; y++){ yearfield.options[y]=new Option(thisyear, thisyear) thisyear+=1 } yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year } </script> This script when the year is selected chooses 2011-2030 but I want like 1900-2011 How do I fix this and then how would I make sure that it isn't blank and then sends this data to one field in my database called "dob" in form "0000-00-00".. thanks.. Hi , I am using date of birth field in my application and i m taking date of birth in yyyy-mm-dd format. I need to calculate age by using this date of birth and should show alert if age is less than 5 years. help me.... Thanks in advance I have a date of birth drop down for 'Day', 'Month' and a text field for Year. How can I get the select value of the drop down and year text field into a single text field, separated by '-'? The single text field would need to update if someone changed the drop down / year selections. Hope someone can help - I'm stumped! I have a form where I have to calculate a future date (end date) from two fields. First the start date and then the number of months. So if the start date is 1/1/2011 and the months given is 12 then the end date should return as 12/31/2011. I can't figure out why it's not returnign a value. Here's what I have: Code: function AddDays() { DaysToAdd=document.getElementById("DaysToAdd").value; startdate=document.getelementbyid("startdate").value; var newdate=new Date(); var newtimems=startdate+(DaysToAdd*730*60*60*1000); newdate.setTime(newtimems); document.getElementById("display").value=newdate.toLocaleString(); } Any insight is appreciated. I am trying to figure out how to calculate the date 30 days ago. I also will need to be able to change the interval. Anyone have a piece of code that does this? If you take a look at the attached image you will see that the person has the choice of picking a membership duration of 3 months, 6 months, or One Year. The Membership Begin date automatically calculates today's date. I want to be able to have the Membership Ends field correctly give the membership ending date based on what Duration is chosen. Ex. 1/05/11 + 3 Months = 4/05/11 Problem: The membership for One Year is value set for 11 because of a discount. I need to add one month to make the date correct. I've tried alot of codes and I'm getting no where! Thank you for the help! List Box name - "Duration" This javascript code is supposedly to show the current date, and show a famous person's birthday on each day. Not sure if I am suppose to have birthdates in js files, or in first files. [CODE]Filename: births.htm Supporting files: functions.js, logo.jpg --> <title>Welcome to Happy Birthday.com</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" type="text/javascript"> var births = new Array(); births[1] = "J.D. Salinger (1919) - Author"; births[2] = "Isaac Asimov (1920) - Author"; births[3] = "Clement Attlee (1883) - 42 Prime Minister"; births[4] = "Floyd Patterson (1935) - Heavyweight boxer"; births[5] = "King Camp Gillette (1855) - Invented safety razor"; births[6] = "Mel Gibson (1956) - Actor"; births[7] = "Millard Fillmore (1800) - 13th US President"; births[8] = "Elvis Aaron Presley (1935) - King of rock 'n' roll"; births[9] = "Richard Nixon (1913) - 37th US President"; births[10] = "George Foreman (1949) - Heavyweight boxing champ"; births[11] = "Alexander Hamilton (1755) - American Founding Father"; births[12] = "Joe Frazier (1947) - Heavyweight boxing champ"; births[13] = "Orlando Bloom (1977) - Actor"; births[14] = "Benedict Arnold (1741) - American"; births[15] = "Martin Luther King (1929) - Civil-rights "; births[16] = "Andre Michelin (1853) - Inventor of rubber tires"; births[17] = "Muhammad Ali (1942) - Boxer Cassius Clay"; births[18] = "David D Kaminsky (1913) - Danny Kaye"; births[19] = "James Watt (1736) - Inventor of the steam engine"; births[20] = "Edwin 'Buzz' Aldrin (1930) - Second man on Moon"; births[21] = "Telly Savalas (1924) - Actor"; births[22] = "Sam Cooke (1935) - Singer"; births[23] = "Princes Caroline (1957) - Royal of Monaco"; births[24] = "John Belushi (1949) - Actor"; births[25] = "Robert Burns (1759) - Scottish poet"; births[26] = "Paul Newman (1925) - Actor"; births[27] = "Amadeus Mozart (1756) - Composer"; births[28] = "Elijah Wood (1981) - Actor"; births[29] = "William McKinley (1843) - American President"; births[30] = "Franklin D. Roosevelt (1882) - American President"; births[31] = "Mario Lanza (1921) - Tenor singer"; births[32] = "Clark William Gable (1901) - Actor"; births[33] = "James Joyce (1882) - Author"; births[34] = "Gertrude Stein (1874) - Author"; births[35] = "Charles Lindbergh (1902) - Aviator"; births[36] = "John Boyd Dunlop (1840) - Inventor of the pneumatic tire"; births[37] = "Ronald Reagan (1911) - 40th US President"; births[38] = "Charles Dickens (1812) - Author"; births[39] = "James Dean (1931) - Actor"; births[40] = "Sandy Lyle (1958) - British golfer"; births[41] = "Harold Macmillan (1894) - 44th UK Prime Min"; births[42] = "Thomas Alva Edison (1847) - Inventor of the electric light bulb"; births[43] = "Abraham Lincoln (1809) - 16th US President"; births[44] = "George Segal (1934) - Actor"; births[45] = "Jimmy Hoffa (1913) - Union Leader"; births[46] = "Galileo Galilei (1564) - Italian astronomer"; births[47] = "John McEnroe (1959) - Tennis player"; births[48] = "Michael Jordan (1963) - Basketball player"; births[49] = "Enzo Ferrari (1898) - Sports car builder"; births[50] = "Prince Andrew (1960) - Queens 3rd child"; births[51] = "Sidney Poitier (1927) - First black Oscar win"; births[52] = "Jilly Cooper (1937) - Author"; births[53] = "George Washington (1732) - 1st US President"; births[54] = "Linda Nolan (1959) - Singer" births[55] = "Steven Jobs (1955) - Software pioneer"; births[56] = "George Harrison (1943) - Ex-Beatle guitarist"; births[57] = "William F Cody (1846) - Buffalo Bill"; births[58] = "Elizabeth Taylor (1932) - Actress Oscar winner"; births[59] = "Barry McGuigan (1961) - Featherweight boxer"; births[60] = "Gioacchino Rossini (1792) - William Tell Overture"; births[61] = "Glen Miller (1904) - Bandleader"; births[62] = "Mikhail Gorbachev (1931) - Soviet President"; births[63] = "Alexander G Bell (1847) - Inventor of telephone"; births[64] = "Patrick Moore (1923) - Astronomer"; births[65] = "William Oughtred (1574) - Inventor of the slide rule"; births[66] = "Valentine Tereshkova (1937) - First woman in space"; births[67] = "Armstrong Jones (1930) - Lord Snowdon (photographer)"; births[68] = "Karl Von Grafe (1787) - Plastic surgery pioneer"; births[69] = "Yuri Gagarin (1934) - First man in space"; births[70] = "Chuck Norris (1942) - Karate film actor"; births[71] = "Sir Harold Wilson (1916) - 46th UK Prime Min"; births[72] = "Liza Minnelli (1946) - Actress"; births[73] = "Joseph Priestley (1733) - Discoverer of oxygen gas"; births[74] = "Albert Einstein (1879) - Theory of relativity"; births[75] = "Andrew Jackson (1767) - 7th US President"; births[76] = "George Ohm (1787) - Measure of electricity"; births[77] = "Gottlieb Daimler (1834) - Inventor of the combustion engine"; births[78] = "Neville Chamberlain (1869) - 40th UK Prime Min"; births[79] = "David Livingstone (1813) - Explorer"; births[80] = "Mr. Rodgers (1928) - Children's entertainer"; births[81] = "Johann Sebastian Bach (1685) - Composer"; births[82] = "Andrew Lloyd Webber (1948) - British songwriter"; births[83] = "Sir Roger Bannister (1948) - First runner to break the four-minute mile"; births[84] = "Steve McQueen (1930) - Actor"; births[85] = "Reginald K Dwight (1947) - Singer Elton John"; births[86] = "Diana Ross (1944) - Singer"; births[87] = "Henry Royce (1863) - Co founder of Rolls-Royce"; births[88] = "Neil Kinnock (1942) - Former Labour leader"; births[89] = "John Major (1947) - 50th UK Prime Min"; births[90] = "Vincent Van Gogh (1854) - Dutch painter"; births[91] = "Gordie Howe (1928) - Hockey player"; births[92] = "William Harvey (1578) - Discoverer of blood circulation"; births[93] = "Hans Chris Andersen (1805) - The Ugly Duckling"; births[94] = "Doris Kappelhoff (1924) - Doris Day (actress)"; births[95] = "Maya Angelou (1928) - Poet"; births[96] = "Lord Joseph Lister (1827) - Introduced antiseptic"; births[97] = "Harry Houdini (1874) - Escape artist"; births[98] = "William Wordsworth (1843) - Poet"; births[99] = "Julian Lennon (1963) - Singer"; births[100] = "Isambard Brunel (1806) - Engineer of the Thames tunnel"; births[101] = "Michel Shalhouz (1932) - Actor Omar Sharif "; births[102] = "Joel Grey (1932) - Actor"; births[103] = "Tom Clancy (1947) - Author"; births[104] = "Garry Kasparov (1963) - British chess champ"; births[105] = "Rod Steiger (1925) - Acotr"; births[106] = "Leonardo da Vinci (1452) - Genius"; births[107] = "Charlie S Chaplin (1889) - Silent comedy actor"; births[108] = "Nikita Krushchev (1894) - Soviet leader"; births[109] = "Hayley Mills (1946) - Child star actress"; births[110] = "Dudley Moore (1935) - Actor 'Arthur' and '10'"; births[111] = "Adolf Hitler (1889) - German leader"; births[112] = "Queen Elizabeth II (1926) - Head of British Commonwealth"; births[113] = "Jack Nicholson (1938) - Actor"; births[114] = "William Shakespeare (1564) - Playwright and Poet"; births[115] = "Barbra Streisand (1942) - Singer"; births[116] = "Ella Fitzgerald (1918) - Singer"; births[117] = "Jet Li (1963) - Actor"; births[118] = "Samuel Morse (1791) - Inventor of Morse Code"; births[119] = "Saddam Hussein (1937) - Deposed Iraq President"; births[120] = "Hirohito (1901) - Emperor of Japan"; births[121] = "Kath Smith (1909) - Singer"; births[122] = "Duke of Wellington (1769) - 23rd UK Prime Min"; births[123] = "Harry (Bing) Crosby (1904) - Singer/Actor"; births[124] = "Arnold G Dorsey (1936) - Engelbert Humperdink"; births[125] = "Michael Barrymore (1952) - Entertainer"; births[126] = "Tammy Wynette (1942) - Singer"; births[127] = "Sigmund Freud (1856) - Psychoanalysis"; births[128] = "Johannes Brahms (1833) - German composer"; births[129] = "Harry S Truman (1884) - 33rd US President"; births[130] = "Glenda Jackson (1936) - Actress"; births[131] = "Fred Astaire (1899) - Actor and tap-dancer"; births[132] = "Phil Silvers (1912) - Actor"; births[133] = "Florence Nightingale (1820) - Crimean war nurse"; births[134] = "Stevie Wonder (1950) - Singer"; births[135] = "Thomas Gainborough (1727) - Landscape painter"; births[136] = "James Mason (1909) - Actor"; births[137] = "Henry Fonda (1905) - Actor"; births[138] = "Grace Jones (1955) - Singer"; births[139] = "Karol Wojtyla (1920) - Pope John Paul II"; births[140] = "Pete Townshend (1945) - Singer"; births[141] = "James M Stewart (1908) - Comedy actor"; births[142] = "Leo Sayer (1948) - Singer"; births[143] = "Laurence Olivier (1907) - Actor"; births[144] = "Joan Collins (1933) - Film & TV actress"; births[145] = "Queen Victoria (1819) - Longest reigning Queen"; births[146] = "Miles Davis (1926) - Musician"; births[147] = "Marion Morrison (1907) - Actor John Wayne"; births[148] = "Vincent Price (1911) - Horror movie actor"; births[149] = "Ian Fleming (1908) - Author"; births[150] = "John F Kennedy (1917) - 35th US President"; births[151] = "Peter the Great (1672) - Emperor of Russia"; births[152] = "Clint Eastwood (1930) - Actor"; births[153] = "Norma Jean Baker (1926) - Marilyn Monroe"; births[154] = "Johnny Weissmuller (1903) - Actor"; births[155] = "King George V (1865) - 2nd son of Edward VII"; births[156] = "Christopher Cockerel (1910) - Inventor of the hovercraft"; births[157] = "John Couch Adams (1819) - British Astronomer"; births[158] = "Robert Falcon Scott (1868) - 1st Brit to South Pole"; births[159] = "Tom Jones (1940) - Singer"; births[160] = "Nancy Sinatra (1940) - Singer"; births[161] = "George Stephenson (1781) - Inventor of the first steam locomotive"; births[162] = "Judy Garland (1922) - Singer"; births[163] = "Vince Lombardi (1913) - Coach of the Green Bay Packers"; births[164] = "George Herbert Bush (1924) - 41st US President"; births[165] = "Tim Allen (1953) - Actor"; births[166] = "Boy George (1961) - Singer "; births[167] = "Mario Cuomo (1932) - Former governor of New York"; births[168] = "Stan Laurel (1890) - Laurel & Hardy duo"; births[169] = "Barry Manilow (1946) - Singer"; births[170] = "Paul McCartney (1942) - Singer"; births[171] = "Blaise Pascal (1623) - French mathematician"; births[172] = "Errol Flynn (1909) - Action-adventure film"; births[173] = "Prince William (1982) - Prince & Princess Wales son"; births[174] = "Meryl Streep (1949) - Actress"; births[175] = "Charles R Darwin (1809) - Theory of evolution"; births[176] = "Jack Dempsey (1895) - Heavyweight boxing"; births[177] = "Eric Arthur Blair (1903) - George Orwell"; births[178] = "William T Kelvin (1827) - Inventor of the absolute temperature scale"; births[179] = "Helen Keller (1880) - Author"; births[180] = "Mel Brooks (1926) - Writer/Actor"; births[181] = "Nelson Eddy (1901) - Singer"; births[182] = "Mike Tyson (1966) - Boxer"; births[183] = "Dianna Spencer (1961) - Princess Diane"; births[184] = "Richard Petty (1937) - Racecar driver"; births[185] = "Tom Cruise (1962) - Actor"; births[186] = "Calvin Coolidge (1872) - American president"; births[187] = "Bjorn Borg (1980) - Wimbledon tennis champion"; births[188] = "Bill Haley (1925) - Singer"; births[189] = "Richard Starkey (1940) - Ringo Starr"; births[190] = "Ringo Starr (1940) - Ex-Beatle drummer"; births[191] = "Sir Edward Heath (1916) - 47th UK Prime Min"; births[192] = "Virginia Wade (1945) - Tennis champion"; births[193] = "Yul Brynner (1917) - Actor"; births[194] = "Josiah Wedgwood (1730) - Blue & white pottery"; births[195] = "Harrison Ford (1942) - Actor"; births[196] = "Gerald Rudolph Ford (1913) - 38th US President"; births[197] = "Rembrandt (1606) - Dutch artist & painter"; births[198] = "Roald Amundsen (1872) - First man to reach the South Pole"; births[199] = "James Cagney (1899) - Actor"; births[200] = "John Glenn (1921) - First man to orbit Earth"; births[201] = "Samuel Colt (1814) - Inventor of the colt revolver"; births[202] = "Sir Edmund Hillary (1919) - First to climb Mt. Everest"; births[203] = "Ernest Hemingway (1899) - Author"; births[204] = "Bob Dole (1923) - Former U.S. Senator"; births[205] = "Monica Lewinsky (1973)"; births[206] = "Amelia Earhart (1898) - 1st woman to fly Atlantic"; births[207] = "Arthur James Balfour (1848) - 33rd UK Prime Min"; births[208] = "Mick Jagger (1944) - Singer"; births[209] = "Joseph Hilary Belloc (1870) - Author"; births[210] = "Beatrix Potter (1866) - Author"; births[211] = "Peter Jennings (1938) - Journalist"; births[212] = "Emily Bronte (1818) - Wuthering Heights"; births[213] = "J. K. Rowling (1965) - Author"; births[214] = "Herman Melville (1819) - Author"; births[215] = "Peter O'Toole (1932) - Lawrence of Arabia"; births[216] = "Stanly Baldwin (1868) - 38th UK Prime Min"; births[217] = "Queen Elizabeth (1900) - King George 6th wife"; births[218] = "Neil Armstrong (1930) - First man on the Moon"; births[219] = "Andy Warhol (1928) - Artist"; births[220] = "Mata Hari (1876) - Spy for the Germans"; births[221] = "Dustin Hoffman (1937) - Actor"; births[222] = "Thomas Telford (1757) - Road & bridge Engineer"; births[223] = "Herbert Clark Hoover (1874) - 31st US President"; births[224] = "Enid Blyton (1897) - Author"; births[225] = "King George 4th (1762) - King of England"; births[226] = "John Logie Baird (1888) - Inventor of television"; births[227] = "John Galsworthy (1867) - Author"; births[228] = "Napoleon Bonaparte (1769) - French leader"; births[229] = "Madonna (1959) - Singer"; births[230] = "May West (1892) - Actress"; births[231] = "Robert Redford (1937) - Actor"; births[232] = "Orville Wright (1871) - Inventor of the first airplane"; births[233] = "Jim Reeves (1924) - Singer"; births[234] = "William Murdock (1754) - Inventor of coal-gas lighting in 1792"; births[235] = "Ray Bradbury (1920) - Author"; births[236] = "Gene Kelly (1912) - Actor/Dancer"; births[237] = "Craig Kilborn (1962) - Actor"; births[238] = "Sean Connery (1930) - Actor"; births[239] = "Robert Walpole (1676) - 1st UK Prime Minister"; births[240] = "Sam Goldwyn (1910) - Film producer"; births[241] = "David Soul (1828) - Actor"; births[242] = "Michael Jackson (1958) - Singer"; births[243] = "Denis Healey (1917) - Politician"; births[244] = "Sir Bernard Lovell (1928) - Inventor of the radio telescope"; births[245] = "Rocky Marciano (1923) - Heavyweight boxer"; births[246] = "Salma Hayek (1968) - Actress"; births[247] = "Alan Ladd (1913) - Actor"; births[248] = "Tom Watson (1949) - Golfer"; births[249] = "Raquel Welch (1940) - Actress"; births[250] = "Britt Ekland (1942) - Actress"; births[251] = "Queen Elizabeth I (1533) - Queen of England"; births[252] = "King Richard I (1157) - Richard the Lion Heart"; births[253] = "William Bligh (1754) - Mutiny on the Bounty"; births[254] = "Arnold Palmer (1929) - US golfing champion"; births[255] = "O. Henry (1862) - Author"; births[256] = "Richard Gatling (1818) - Inventor of the Gatling Gun"; births[257] = "Claudette Colbert (1905) - Actress"; births[258] = "Jack Hawkins (1910) - British film actor"; births[259] = "Agatha Christie (1891) - Detective storywriter"; births[260] = "B. B. King (1925) - Musician"; births[261] = "John Ritter (1948) - Actor"; births[262] = "Samuel Johnson (1709) - 18th century writer"; births[263] = "George Cadbury (1839) - Chocolate manufacturer"; births[264] = "Sophia Loren (1934) - Italian film actress"; births[265] = "H G Wells (1866) - Science fiction novelist"; births[266] = "Michael Faraday (1791) - Inventor of the electric generator 1831"; births[267] = "Julio Iglesias (1943) - Singer"; births[268] = "Anthony Newley (1931) - Actor"; births[269] = "Meat Loaf (1947) - Singer"; births[270] = "George Gershwin (1898) - Composer"; births[271] = "Mike Schmidt (1949) - Baseball player"; births[272] = "Lech Walesa (1943) - Founder of Solidarity"; births[273] = "Horatio Nelson (1758) - Commander"; births[274] = "Johnny Mathis (1935) - Singer"; births[275] = "Jimmy Carter (1924) - 39th American President"; births[276] = "Mahatma K Gandhi (1869) - Hindu spiritual leader"; births[277] = "Chubby Checker (1941) - Singer"; births[278] = "Buster Keaton (1895) - Silent film comedy actor"; births[279] = "Donnald Pleasence (1919) - Actor"; births[280] = "George Westinghouse (1846) - Inventor of the railway air brake"; births[281] = "Yo-Yo Ma (1955) - Musician"; births[282] = "R. L. Stine (1943) - Author"; births[283] = "John Lennon (1940) - Beatles song writer"; births[284] = "William Morris (1877) - Motoring pioneer"; births[285] = "Henry J Heins (1844) - Food products manufacturer"; births[286] = "Ramsay MacDonald (1866) - 39th British Prime Minister"; births[287] = "Margaret H Thatcher (1925) - First woman Prime Minister"; births[288] = "Dwight Eisenhower (1890) - 34th American President"; births[289] = "John L Sullivan (1858) - World heavyweight boxing champion"; Resolution if interested: Code: <head> <title>Lab8</title> <script src="arrays.js" type="text/javascript"></script> <link href="css.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function amountTotal() { var totalDonations = 0; for (var i = 0; i < amount.length; i++) { totalDonations += amount[i]; } return totalDonations; } </script> </head> <body> <table id="donations" rules="rows"> <tr> <th> Date </th> <th> Name </th> <th> Amount </th> <th> Address </th> </tr> <script type="text/javascript"> for (var i = 0; i < amount.length; i++) { if (i % 2 == 0) document.write("<tr>") else document.write("<tr class='yellowrow'>"); document.write("<td>" + date[i] + "</td>"); document.write("<td>" + firstName[i] + lastName[i] + "</td>"); document.write("<td>" + amount[i] + "</td>"); document.write("<td>" + street[i] + "<br />" + city[i] + "," + " " + state[i] + " " + zip[i] + "</td>"); } document.write("</tr>") </script> </table> <table id="totalsTable"> <tr> <th colspan="2"> Summary </th> </tr> <tr> <td> Contributions </td> <td class="amt"> <script type="text/javascript"> document.write(amount.length); </script> </td> </tr> <tr> <td> Amount </td> <td class="amt">$ <script type="text/javascript"> var totalTotal = amountTotal(); document.write(totalTotal); </script> </td> </tr> </table> </body> </html> I have a seperate .js sheet with some arrays on them (firstName, lastName, date, amount, city, state, zip) and I am trying to populate a table with these indexes. The 'yellowrow' highlights everyother row which is called out in my css sheet. My header rows fill in but not the rest. Here is the link for the site actually posted on the web. Code: <body> <table id="donations" rules="rows"> <tr> <th>Date</th> <th>Name</th> <th>Amount</th> <th>Address</th> </tr> <script type="text/javascript"> for (var i = 0; i < amount.length; i++) { if (i % 2 == 0) document.write("<tr>") else document.write("<tr class='yellowrow'>"); document.write("<td>" + date(i) + "</td>"); document.write("<td>" + firstName(i) + lastName(i) + "</td>"); document.write("<td>" + amount(i) + "</td>"); document.write("<td>" + "<br />" + city(i) + "," + state(i) + zip(i) + "</td>"); } document.write("</tr>") </script> </table> </body> I am trying to populate a listbox using Javascript. The listbox is populated using the xml response from ajax request. Below is the code used for the same Code: var xmlDoc = xmlhttp.responseXML; for (var i = 0; i < xmlDoc.getElementsByTagName("id").length; i++) { traderlists.add(new Option(xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("id")[i].childNodes[0].nodeValue)); } This works fine for me. But i am facing performance issue here. some ajax requests retrieves xmls with around 11,000 nodes and this takes too much of time to populate the listbox. Can anyone please advice me with an better solution? I really need help with this. I really don't know how to make this work. I need to populate a drop down menu with a value passed through the browser if it's passed. so the browser URL will look like: domain.com/?referer=YellowPagesOnline I need to capture the referer value from the browser store it into a cookie. If the cookie is set and then populate the drop down on the page with the cookie. If it's not set then a list of sources should appear. So I already have the code to grab the string and store it in a cookie but I'm not sure how to do the initialization of the drop down with the cookie value. This is what I have... Code: <script> //Get the referer string out of the URL function getQuerystring(key, default_) { if (default_==null) default_=""; key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regex = new RegExp("[\\?&]"+key+"=([^&#]*)"); var qs = regex.exec(window.location.href); if(qs == null) return default_; else return qs[1]; } //Set the cookie for 30 days function SetCookie(cookieName,cookieValue,nDays) { var today = new Date(); var expire = new Date(); if (nDays==null || nDays==0) nDays=1; /* expire.setTime(today.getTime() + 3600000*24*nDays);*/ expire.setTime(today.getTime() + (1000 * 60 * 60 * 24 * 30)); document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString(); } //Put the cookie on the user's computer function putcookie() { var val = getQuerystring('referer'); if(val !=""){ if (document.cookie.length == 0) { SetCookie('referer', val, 1); alert(val); } } alert(document.cookie); } putcookie(); getCookie(name); //If there is a cookie then get the cookie function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; if(document.SECatJax.referer.length > 0) { document.SECatJax.referer.value = unescape(document.cookie.substring(c_start,c_end)); return false; } alert(document.cookie); } } document.SECatJax.referer.value = 'Website'; } The dropdown to appear if there isn't a cookie is Code: <select name="source_code" size="1" id="source_code" class="select_2" style="display:none"> <option value="" selected="selected">--</option> <option value="Direct Mail">Direct Mail</option> <option value="High School Presentation">High School Presentation</option> <option value="Search Engine">Internet Search</option> <option value="Newspaper">Newspaper</option> <option value="Poster">Poster</option> <option value="Radio">Radio</option> <option value="Referral">Referral</option> <option value="TV">TV</option> <option value="Yellow Pages">Yellow Pages</option> </select> The drop down to appear if there is a cookie is[CODE]<select name="source_code2" size="1" id="source_code2" class="select_2" style="display:none"> <option value="YellowPagesOnline" selected="selected">YellowPagesOnline</option> </select>[CODE] Can someone help me with this please? Thanks. I have a div what will contain a various number on images and i need to put all their src's into an array. Is this doable? Heres the code Code: <div id="imageHolder"> <!-- ONLY CHANGE THE SRC, NOTHING ELSE --> <div style="width:770px;height:400px;overflow-y:auto;margin-bottom:5px;"> <img src="http://wholesalepadlocks.co.uk/ebayImages/AU080.JPG" alt="" width="750" id="mainImage"/><br /><br /> </div> <img src="http://wholesalepadlocks.co.uk/ebayImages/au080a.jpg" alt="" width="240" height="120" onmouseover="Images = this.src;alert(Images)" /> <img src="http://wholesalepadlocks.co.uk/ebayImages/au080b.jpg" alt="" width="240" height="120" onmouseover="Images = this.src;alert(Images)"/> <img src="http://wholesalepadlocks.co.uk/ebayImages/AU080.JPG" alt="" width="240" height="120" onmouseover="Images = this.src;alert(Images)"/> </div>Ignore the onmouseover code i was attempting to do this but so far no luck :P I have a check box right now that calls an onClick event. Here is the Input: Code: <input name="usePad" type="checkbox" value="usePad" id="usePad" onclick="showBind('padShow','padOk')" /> Here is the Script: Code: var xmlhttpshowBind; var showBindDiv; function showBind(BindPage,BindDiv) { xmlhttpshowBind=GetXmlHttpObject(); if (xmlhttpshowBind==null) { alert ("Browser does not support HTTP Request"); return; } var url="/scripts/"+BindPage+".php"; showBindDiv=BindDiv; xmlhttpshowBind.onreadystatechange=showBindGet; xmlhttpshowBind.open("GET",url,true); xmlhttpshowBind.send(null); } function showBindGet() { if (xmlhttpshowBind.readyState==4) { document.getElementById(showBindDiv).innerHTML=xmlhttpshowBind.responseText; } } It works great to fill the div called for, but I would like it to remove the div contents if it's unchecked, I'm not sure how to do this?? Any help would be appreciated! Thank you in advance! hello i am trying to fire a form which after the call to retrieve the data, populate the form with the data. i can see from firebug that the json data is being captured, but cannot seem to be able to populate the form with it. i am using a jquery plugin facybox, that opens the form, but the fields are blank. i have attached my code and would be grateful if someone could tell me where i am going wrong? many thanks js code Code: <script type="text/javascript"> function edit(com, grid) { if (com == 'Edit') { if($('.trSelected').length>0){ if($('.trSelected').length>1){ alert('Please select just one row'); return; } var items = $('.trSelected'); var itemlist =''; for(i=0;i<items.length;i++){ itemlist+= items[i].id.substr(3); } $.ajax({ type: "POST", dataType: "json", url: "tempcontact.php", data: "items="+itemlist, success: function(data){ document.getElementById('id').value = data.id; document.getElementById('email').value = data.email; $("#flex1").flexReload(); } }); /*and so on then you can call facybox*/ jQuery.facybox({ div: "#editform"}); } else{ alert('Please select a row to edit.'); } } } </script> form Code: <div id="editform" style="display:none;"> <form action="conedit.php" method="post" class="webform"> <fieldset> <legend><span>Update Contact</span></legend> <br /> <div id="dataText">Please delete the fields if there is no data 'No data to display'.</div> <label for="id">ID:</label> <input id="id" name="id" class="text" type="text" value="" /> <label for="name">Full Name:</label> <input id="name" name="name" class="text" type="text" value="" /> <label for="email">Email address:</label> <input id="email" name="email" class="text" type="text" value="" /> <label for="phone">Telephone:</label> <input id="phone" name="phone" class="text" type="text" value="" /> <label for="mobile">Mobile:</label> <input id="mobile" name="mobile" class="text" type="text" value="" /> <label for="fax">Fax:</label> <input id="fax" name="fax" class="text" type="text" value="" /> <label for="notes">Notes:</label> <textarea name="notes" cols="25" rows="3"></textarea> </fieldset> <input class="submit" type="submit" name="submit" value="Update" /> </form> </div> Hello guys, How to populate array from dropdownlist? I've tried like this var array = new array(); var d = document.getElementById("DropDownListl"); for (var i = 0; i < d.options.length; i++) { array[i] = d.options[i].value; } Thank you <!-- *** NEED HELP PASSING VALUE id TO POPULATE SUBRECORDS *** --> <!-- *** See line #51 to #55 *** --> <?php session_start(); ob_start(); if($_SESSION[userdetails]->role != "Admin") { die("Access Denied!"); } require_once("includes/connect.php"); // Check if he has the right info. $sql = sprintf("SELECT * FROM members ORDER BY username ASC", $_SESSION[userdetails]->id); $query = mysql_query($sql); // You are now connected ?> <head> <html> <head> <title>Split ListBox Text To Text Boxes</title> <script type="text/javascript"> <!-- archaic format: language="javascript" --> function SplitText (info) { if (info == '') { return; } var tarr = info.split(","); document.getElementById('tBox1').value = tarr[0]; document.getElementById('tBox2').value = tarr[1]; document.getElementById('tBox3').value = tarr[2]; document.getElementById('tBox4').value = tarr[3]; } </script> </head> <body> <form name="convert"> <p style="margin: 2px"> <p><select name="Groups" style="width: 176; height: 19; border: 1px solid #C0C0C0 ; font-size: 11px; font-family:Arial" size="1" onChange="SplitText(this.value)"> <option>===Select Group===</option> <?php $sql1 = mysql_query("SELECT * FROM qw_groups"); while($r1=mysql_fetch_assoc($sql1)){ $f1 = $r1[id]; $f2 = $r1[GroupName]; echo "<option value='$f1,$f2,,'>$f2</option>"; } echo "</select>"; ?> <p><select name="GroupItems" style="width: 176; height: 19; border: 1px solid #C0C0C0 ; font-size: 11px; font-family:Arial" size="1" onChange="SplitText(this.value)"> <option>===Select Group Item===</option> <?php // **** IS IT POSSIBLE TO PASS THE VALUE "$f1" FROM GROUPS TO GROUPITEMS **** // **** I WANT TO POPULATE THE SECOND DROPDOWN LIST WITH SUB-RECORDS WITHOUT SUBMIT /POST /REFRESH /OR RELOAD **** // WHERE id = $f1 ?? maybe some java code id = $val onChange ?? $sql2 = mysql_query("SELECT * FROM qw_groupitems WHERE id = $f1"); while($r2=mysql_fetch_assoc($sql2)){ $f3 = $r2[Subid]; $f4 = $r2[GroupItem]; echo "<option value='$f1,$f2,$f3,$f4'>$f4</option>"; } echo "</select>"; ?> </p> <!-- Input selected data from listBox --> <p style="margin: 2px"> <input type="text" name="textbox1" id="tBox1" value=""><br> <input type="text" name="textbox2" id="tBox2" value=""><br> <input type="text" name="textbox3" id="tBox3" value=""><br> <input type="text" name="textbox4" id="tBox4" value=""><br> </p> </form> </body> </html> I have a table where when the cursor passes/hovers over a cell, the current cell, as well as the top cell in its column and the first cell in its row change backgroundColor. I have text fields outside the table which I want to populate with the contents of the cells affected by the mouseover event. So as the mouse moves over different cells, the contents of the text fields changes accordingly. I've got the backgroundColor to change, but when I try to assign the contents of the cells to the text fields, nothing happens. The change of backgroundColor even stops working. This is the code I'm usign to populate the fields. Code: document.getElementById("tableID").textfieldID.value = Col1Cell[0].innerHTML; document.getElementById("tableID").textfieldID.value = HeaderCell[n].innerHTML; document.getElementById("tableID").textfieldID.value = this.innerHTML; I'm traversing through the <th> and <td> tags to find the header cell HeaderCell[n] and first column cell Col1Cell[0] associated with the current cell. If I leave out these lines the backgroundColor changes, if I use them, nothing happens at all. Can't figure out why. Any suggestions? I have two slightly different forms on the same page, but I want the values in form1 to auto populate the same form fields in form2. 1 field is a text field, the rest are drop down menus. How would I accomplish this? Link to tutorial would be much appreciated. Thanks
Hi, I'm working on a menu update form. I'm pulling the existing data from mysql and posting it into a form, using php. This works fine. But now I want the user to be able to modify the data and perform and update query to the database with the changes. I cannot figure out how to get the modified php text box data into my html form text boxes so I can run an update query. I would be ok with a button that transfers the php text box data to the html form data. Hope this is clear what I'm trying to do, seems simple enough, but I can't figure it out. Thanks in advance for any ideas. I have a web form that requests a user full name and email address. What I would like to do is when the user fills in the full name in one input box, I would like to take the full name and populate the email address field as such. "first.last@allstate.com". So pretty much split the full name and popluate email address field "first.last@allstate.com". Tracy Hi guys, I am facing the above problem for a chatroom app that I am making. People will enter and exit the room any time they want, so i need a member list that updates itself to reflect this on the screen of all users that are in the chatroom. What i have thought of, is to have JS call a PHP function on specific intervals, and that PHP function will retrieve user data from a database and pass it to JS to display on the list. Is this method advisable? Are there any more suitable ways of doing this? I am thinking of applying the same theory for displaying and retrieving chat messages, but i get the feeling that something's missing for this, or maybe this method is not right for displaying messages. |