Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Sending a message to the server and changing text on a page when a button is pressed

Scenario ...
* I wish to provide a button on my page that signals when it's pressed back to the server
* I wish the server to log the button press (a vote, perhaps) but not refresh the page
* I wish to change the text on the page to give visual feedback that the button has been pressed

Easy enough, but hard to find all in one example.

I've just added a "like" facility on to the First Great Western Coffee Shop forum.

Here's the HTML for each "like" button" (shown over multiple lines to make it easier to read):

  [<a href=/coffeeshop/lyke.php?id=154834
  onClick='document.getElementById("txt154834").innerHTML="yum!";'>
  <span id='txt154834'>like</span></a>]


The reference number in the example is the message number that the like button is attached to; this HTML is generated by a modified PHP forum script so that the receiving lyke.php knows [i]what[/i] the user has liked. It uses the forum cookie to identify [i]who[/i] is doing the liking, and registers all likes in a MySQL database to stop users registering lots of votes for the same post.

In order to prevent the browser redrawing the page, the lyke.php includes the following header:

  header("HTTP/1.1: 204 No Content");

And (as that might suggest) there is no content. the onClick Javascipt changes the work "like" into "yum!" to indicate that the button was pressed.
(written 2014-05-23, updated 2014-05-26)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
W602 - Web and Intranet - Client Side Technologies
  [4310] Problem ... I want to print a series of numbered forms - (2014-10-05)
  [3128] How does your browser find out about itself? - (2011-01-11)
  [2628] An example of an injection attack using Javascript - (2010-02-08)
  [2390] Dynamic / changing images on your web page - (2009-09-01)
  [1814] Javascript/HTML example, dynamic server monitor - (2008-09-28)
  [1813] Ajax - going Asyncronous and what it means - (2008-09-28)
  [1812] Starting Ajax - easy example of browser calling up server data - (2008-09-27)
  [1749] Using server side and client side programming together - (2008-08-11)
  [1681] Adding a button to a web page to print the page - (2008-06-18)
  [1322] Flash - is it available to your web page? - (2007-08-26)
  [522] Javascript events - a good example - (2005-12-09)
  [411] Javascript examples (some PHP and MySQL too) - (2005-08-13)

W603 - Web and Intranet - Server Side Technologies
  [3915] How does PHP work? - (2012-11-07)
  [3705] Django Training Courses - UK - (2012-04-23)
  [2282] Checking robots.txt from Python - (2009-07-12)
  [2055] Effect on server when memory runs out and swapping starts - (2009-02-26)
  [1615] PHP training courses every month - (2008-04-18)
  [1554] Online hotel reservations - Melksham, Wiltshire (near Bath) - (2008-02-24)
  [1365] Korn Shell scripts on the web - (2007-09-25)
  [1355] .php or .html extension? Morally Static Pages - (2007-09-17)
  [1031] robots.txt - a clue to hidden pages? - (2007-01-13)
  [1020] Parallel processing in PHP - (2007-01-03)
  [732] Where is a web site visitor browsing from - (2006-05-24)
  [653] Easy feed! - (2006-03-21)
  [642] How similar are two words - (2006-03-11)


Back to
Swindon to Weymouth - by train, the traditional way - 2014
Previous and next
or
Horse's mouth home
Forward to
Future Swindon - Westbury train services. At current level into the future?
Some other Articles
A different vision for the future
Making use of huge data, object orientation, unit testing and frameworks
Upcoming public courses from Well House Consultants
Future Swindon - Westbury train services. At current level into the future?
Sending a message to the server and changing text on a page when a button is pressed
Swindon to Weymouth - by train, the traditional way - 2014
Eurpoean Elections, and other elections ahead. Some thoughts on campaigns and policies
String formatting in Lua - string.format as a wrapper for sprintf
Dot or Colon separator between table name and member in Lua - what is the difference?
Lazy operators in Lua - what they mean, and examples
4734 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4277_Sen ... essed.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat