Welcome, Guest
  • Page:
  • 1
  • 2

TOPIC: Writing a dynamic prompt script

Writing a dynamic prompt script 3 years, 5 months ago #3211

Once I get this working, I intend to package it and post it for you guys. But I need a little help.

I'm trying to write a small script to have form prompts, like the more professional sites use. An example is:

(imagine this line in a form field)

Your Name_____

Click on the box, and it just shows:

______________

So it deletes the input value to make room for what you type. Most importantly, it must not delete what the user puts in there if they blur then re-click on the field.

Also, I tried to make it so that each element stores its initial value as a global property, instead of making it a variable in the function; so that each individual form field would remember its individual prompt.

The script I've written looks like this:

function irs_prompt(element,action) {
if (element.init_value_set==="") {
element.init_value_set=1;
if (element.init_value==="") {
element.init_value=element.value;
}
}
if (action == "click") {
if (element.value == element.init_value) {
element.value = "";
}
}
if (action == "blur") {
if (element.value === "") {
element.value = element.init_value;
}
}
}


And it does nothing at all. I've been scratching my head over this; I've got the parameters of the form object set correctly, i.e. function name equals script name, and the 'click' and 'blur' checkboxes are checked (I'm using the sample contact form name field to test, and I've removed the 'get focus' initial script) so I have to be failing in my javascript somehow. However, I'm no scripting guru, so I just can't see what I'm doing wrong right now. Does anybody else see what's failing here?
Last Edit: 3 years, 5 months ago by CircularLogician.

Re:Writing a dynamic prompt script 3 years, 5 months ago #3284

first of all there can't be 3x '='

if (element.value === "")


compare operator is '==' so

if (element.value == "")


Check it if this is not mistake made by this forum script.
  • b0rek
  • OFFLINE
  • Junior Boarder
  • Posts: 20
  • Karma: 1
Last Edit: 3 years, 5 months ago by b0rek.

Re:Writing a dynamic prompt script 3 years, 5 months ago #3291

For starters add ActionScript to your inputbox (named foo) for Blur and Focus

function ff_fk_foo_action(element, action)
{
    switch (action) {
        case 'blur':
            if(element.value=='') element.value='Your prompt';
            break;
        case 'focus':
            if(element.value=='Your prompt') element.value='';
            break;
        default:;
    } // switch
} // ff_fk_name_action



This works nicely. Maybe it is worth consider to parametrize it so it could be added to Script Library?
  • b0rek
  • OFFLINE
  • Junior Boarder
  • Posts: 20
  • Karma: 1

Re:Writing a dynamic prompt script 3 years, 5 months ago #3381

Yeah, parameterizing it was the goal. In fact, what I'm trying to do is get it to read the initial value of the textfield and keep that in a stored variable; otherwise, I have to write the same script with a different prompt for every field in the form, and that can bloat the code immensely.

The script I wrote didn't work with '==' or '==='; I used Jlint on it, and it had suggested ===, so that's how I ended up using it. I agree, == is probably the right way to do it.
  • CircularLogician

Re:Writing a dynamic prompt script 3 years, 5 months ago #3382

Er, Actionscript? As in flash?

Re:Writing a dynamic prompt script 3 years, 5 months ago #3383

Are you kidding, right?

Action Script - in Breezing Forms, script connected to action on form element. Actions: Click, Blur, Change, Focus, Select.
  • b0rek
  • OFFLINE
  • Junior Boarder
  • Posts: 20
  • Karma: 1
  • Page:
  • 1
  • 2
Moderators: TheMuffinMan, ForumSupport
Time to create page: 4.00 seconds

Facebook Discount - 40% Off!

Fans of our Facebook page here are entitled to get a 1-year-subscription for the price of a 6-months!

Steps to take:

  • Become a fan on Facebook (Like) here
  • Purchase a 6-months-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of your like and we'll upgrade to the 1-year-subscription

Joomla!® Forms Discount - 40% Off!

Already purchased a forms extension from a different vendor but your requirements changed and now you need a forms extension that is capable of more than just the standards? We help you to keep the costs for a change under control: Get a 40% discount on our professional membership plan! -- meaning timely unlimited access to all current and future commercial extensions, breezingforms themes & apps and Joomla!® templates at crosstec.de, including 1 year of support -- without any website limitations -- Just prove that you previously purchased another forms extension for Joomla!® from a different vendor and you are qualified.

Steps to take:

  • Purchase a 1-year-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of the purchase for the other form vendor and we'll upgrade to the professional-subscription

About

Crosstec GmbH & Co. KG

Bergisch-Gladbacher-Str. 829

51069 Cologne, Germany

Imprint