Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2008, 02:56 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
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.

Reply With Quote
  #2 (permalink)  
Old June 23rd, 2008, 03:36 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old June 23rd, 2008, 07:17 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
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.

Reply With Quote
  #4 (permalink)  
Old June 24th, 2008, 08:06 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:13 PM.


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