Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2008, 02:56 PM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default should I use AJAX to make forms that...

have input fields where the initial text (stuff like "please type your first name here") disappears when the user either does a mouseover or changes focus to the field?

I'm thinking it should be possible to simply hook up each form field with a standardised javascript function which 'wipes' the content from the form field, then hands back focus to it, after setting a trigger variable to false or something...


the pseudo-code I envisage would be something like the following:

<head>
standard AJAX xmlhttpresponseobject stuff...

<script language=javascript>

var toggle = false
formfield_wiper (fieldName, toggle){

IF toggle = true then

document.form(fieldName).innerHTML = "";

(do I need an else?)
}
</javascript>
</head>
<body>
<form>
  <input type="text" name="fname" onFocus**="formfield_wiper(fname, true)>
</form>
</body>


would greatly appreciate any and all help as I am something of a complete AJAX novice.



**obviously I could change it to a onmouseover state, but I suspect that it'd end up calling the function from the page a lot, for no good reason, as the user absent-mindedly moves their mouse over the form.

 
Old June 23rd, 2008, 03:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There isn't really anything AJAX about this, aside from the J. This is purely a javascript client-side watermark behavior.

One thing you may want to add is something that remembers what the original watermark value is. When the user enters the field then leaves it without entering anything, or clears it then leaves, you may want to restore the watermark. Due to the flexibility of the javascript model, it's easy to just add a property/field to the textbox itself to save the old value. You can then check in the onBlur handler if the value is empty, you restore the watermark.

-Peter
compiledthoughts.com
 
Old June 23rd, 2008, 07:17 PM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ah, I was thinking the xmlhttpresonseobject would be necessary to effect the changes in the fields, once they've already been rendered by the browser.

I thought that I might be able to make more complex changes later like using radio buttons and adding/removing fields in response to the choices the user makes, without refreshing the page.

 
Old June 24th, 2008, 08:06 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You only need to use XmlHttpRequest when you actually need to call the server. DHTML has been around for a long time and allows you to do a plethora of dynamic changes to the client page without every going back to the server.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Recommend an AJAX IDE - JoyiStar AJAX WebShop. kingstar Ajax 4 December 15th, 2006 05:12 AM
Make fun of my AJAX Site SomeGuy3 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 July 13th, 2006 02:54 PM
new Ajax article: Creating an Ajax Search Widget jminatel Ajax 0 May 11th, 2006 02:50 PM
Let user make forms and controls smang VB.NET 2002/2003 Basics 0 September 2nd, 2005 04:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.