Jump to content

[SOLVED] Input Field intitial text


scottybwoy

Recommended Posts

Hi peeps,

 

I'd like to create an input field that has some text in that dissapears on click and re-appears if no text was added and also go blank if the form is sent.  Like this example where it says "refine your search"

 

Does anyone know what the initial input text label is called, or have a tutorial I can follow to do it. Or just show me ;)

 

Thanks for your help

Link to comment
Share on other sites

Why don't you take a look at their source code? They are using two event handlers, onblur and onfocus. It's just a matter of setting the appropriate JavaScript in them.

 

<input type="text" name="something" id="something" value="Search..." onfocus="javascript:if(this.value=='Search...'){ this.value = ''; }" onblur="javascript: if(this.value == ''){ this.value = 'Search...'; }" />

Link to comment
Share on other sites

OK Thanks,

 

I have copied their code, made a few ammendments and stuck it in my script.  But IE7 gives an object expected error on the $ character on the line pointed out in the code below :

<<!-- This line here //--> $(document).ready(
function() {
	searchBox();
}
);

function searchBox() {
$("#subQuery").focus(
	function() {
		if(this.value=='<?php echo REDIFINE_RESULTS; ?>') {
			this.value='';
		}
	}
);

$("#subQueryButton").click(
	function() {
		if($("#subQuery").val()=='<?php echo REDIFINE_RESULTS; ?>') {
			$("#subQuery").val('');
		}
	}
);

$("#subQuery").blur(
	function() {
		if(this.value=='') {
			this.value='<?php echo REDIFINE_RESULTS; ?>';
		};
	}
);
}

// Here is the HTML

<input id="subQuery" type='text' name='keywords' value="<?php echo REDIFINE_RESULTS; ?>" class='fieldValue' style='width:42%; border:1px solid #3f547f;'>
<?php echo tep_image_submit('button_search.gif', IMAGE_BUTTON_SEARCH, 'name="subsearch"') . tep_draw_hidden_field('search_in_description', '1');

 

Sorry my javascript expertise is very basic,  I don't even know why there is a $ character or what it means?  So can anyone point me out in the right direction?  Thanks

Link to comment
Share on other sites

OK Thanks,

 

I have copied their code, made a few ammendments and stuck it in my script.  But IE7 gives an object expected error on the $ character on the line pointed out in the code below :

<<!-- This line here //--> $(document).ready(
function() {
	searchBox();
}
);

function searchBox() {
$("#subQuery").focus(
	function() {
		if(this.value=='<?php echo REDIFINE_RESULTS; ?>') {
			this.value='';
		}
	}
);

$("#subQueryButton").click(
	function() {
		if($("#subQuery").val()=='<?php echo REDIFINE_RESULTS; ?>') {
			$("#subQuery").val('');
		}
	}
);

$("#subQuery").blur(
	function() {
		if(this.value=='') {
			this.value='<?php echo REDIFINE_RESULTS; ?>';
		};
	}
);
}

// Here is the HTML

<input id="subQuery" type='text' name='keywords' value="<?php echo REDIFINE_RESULTS; ?>" class='fieldValue' style='width:42%; border:1px solid #3f547f;'>
<?php echo tep_image_submit('button_search.gif', IMAGE_BUTTON_SEARCH, 'name="subsearch"') . tep_draw_hidden_field('search_in_description', '1');

 

Sorry my javascript expertise is very basic,  I don't even know why there is a $ character or what it means?  So can anyone point me out in the right direction?  Thanks

 

Their code is using a framework, most likely Prototype or jQuery.  Look at their script tag(s)...do they include any other JavaScript files?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.