It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Optimise Function

Optimise Function

Postby Shaf on Sun Aug 03, 2008 12:48 am

Hi Guys,

I have two functions which do pretty much the same thing. Take a look at the code first:

Code: Select all
/*OnFocus text in SearchBox removed, OnBlur text is re-added to textbox*/
function SearchBox(nm) { nm.value != 'Search Contacts' && nm.value != '' ? nm /*Do Nothing*/ : nm.value = ''; }
function SearchBoxBlur(nm) { nm.value == '' ? nm.value = 'Search Contacts' : nm /*Do Nothing*/; }

/*Same as above two function except for header search box*/
function SearchBox2(nm) { nm.value != 'Search Letters' && nm.value != '' ? nm /*Do Nothing*/ : nm.value = ''; }
function SearchBoxBlur2(nm) { nm.value == '' ? nm.value = 'Search Letters' : nm /*Do Nothing*/; }


For one of the search boxes the value is "Search Letters" the other is "Search Contacts". I tried to consolidate it into one function and use an OR for the two different possilibities but that didnt work (Didnt give any errors either). How can I make the code more efficient ?



.
Shaf
 
Posts: 5
Joined: Fri Jul 25, 2008 10:47 pm

Who is online

Users browsing this forum: No registered users and 4 guests