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
https://forums.phpfreaks.com/topic/131616-solved-input-field-intitial-text/
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...'; }" />

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.