Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass a value using the onFocus event handler

Status
Not open for further replies.

awieland

Programmer
Apr 18, 2005
36
0
0
US
I need a function for my onFocus call, see below. I am trying to pass the text in my search box and assign it to the variable labeled SEARCH. This varible will be called by another page, which uses the following <cfoutput>#search#</cfoutput> to call the variable.

I just need to get the javascipt function to work?

Thank you, awieland

<form action="index.cfm" method="get" >

<label>search
<input name="search2" type="text" value="SEARCH" onFocus="if(this.value=='SEARCH')this.value='';" size="15" />
</label>
<input name="search" type="Image" src="../resources/images/but_go.gif" value="submit" />

</form>

********************************************************

<script type="text/javascript" language="JavaScript">

function if(this.value=='SEARCH') {
document.Form.search2.value = SEARCH
}

</script>
 
Not quite sure what you are trying to do but here we go.
Code:
<script type="text/javascript">
<!--//
getValue() {
    alert(document.this_form.search2.value);
}
//-->
</script>

<form name="this_form" onSubmit="getValue()">
<input type="text" name="search2" value="SEARCH">
<input type="image" src="../resources/images/but_go.gif">
</form>

M. Brooks
 
or using the onFocus event handler
Code:
<script type="text/javascript">
<!--//
getValue(value) {
    alert(value);
}
//-->
</script>

<form name="this_form">
<input type="text" name="search2" value="SEARCH" onFocus="getValue(this.value)">
<input type="image" src="../resources/images/but_go.gif">
</form>

M. Brooks
 
mbrooks,

Can you leave my onFocus="if(this.value=='SEARCH')this.value='';" as is because on my next page index.cfm I am using the following to call the SERACH variable. So, I am only looking to adjust my javascript function on the form page to pass the variable?

*****************************************
search_form2.cfm: form page
*****************************************

<script type="text/javascript" language="JavaScript">

function if(this.value=='SEARCH') {
document.Form.search2.value = SEARCH
}

</script>

<form action="index.cfm" method="get" >

<label>search
<input name="search2" type="text" value="SEARCH" onFocus="if(this.value=='SEARCH')this.value='';" size="15" />
</label>
<!--- <label>search
<input name="search2" type="text" value="SEARCH" size="15" />
</label> --->
<input name="search" type="Image" src="../resources/images/but_go.gif" value="submit" />

</form>

****************************************************
index.cfm code: action page that passes the variable
****************************************************

<META HTTP-EQUIV="refresh" content="0;URL=search.cfm?searchstring=<cfoutput>#search#</cfoutput>

<cfoutput>

<table>
<tr>
<td>&nbsp;<b><font color="000066" size="+1">Searching......</font> "<font color="000066">#search#</font>"<br>&nbsp;Please Wait...</b>
</td>
</tr>
<tr><td height="300px" valign="top"><hr color="000000" width="500" align="left"></td></tr>
</table>

</cfoutput>
 
Code:
<script type="text/javascript">
<!--//
getValue(value) {
    var result = (value == 'SEARCH') ? ";" : value;
    alert(result);
}
//-->
</script>

<form name="this_form">
<input type="text" name="search2" value="SEARCH" onFocus="getValue(this.value)">
<input type="image" src="../resources/images/but_go.gif">
</form>

M. Brooks
 
mbrooks,

I am getting a javascript error,

Error Expected ';'
line 43

41 <script type="text/javascript">
42 <!--//
43 getValue(value) {
44 var result = (value == 'SEARCH') ? ";" : value;
45 alert(result);
46 }
47 //-->
48 </script>

Thank you, awieland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top