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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i need help writing a function...

Status
Not open for further replies.

macmac1

Programmer
Jan 20, 2002
11
US
I need to write a function that will do the following...

user enters an number in an input field..
user then clicks out of input field...
I need to get the value out of the input field with out submiting the entire page.(i just want one of the form elements to submit.)

Thanks
Calvin Click
 
You have two options depending on how you want the data to be manipulated.

1) Event driven function applied to TextField_Change()
You can drive code here that will be driven every time the user enteres a new value for the text field.

2) Event driven function applied to TextField_LostFocus()
Once the user has entered whatever value in the text field, and either TAB'ed out of the field or pressed enter, the value is captured in this function

Here is a simple sample:

Function MyTextField_Change()
MsgBox me!MyTextField
End Function

: Every time you enter a Char or Number, Space or whatever, the msgbox will pop up to display the contents of the field

Function MyTextField_LostFocus()
MsgBox Me!MyTextField
End Function

:Once the user exits the field (by TAB, Enter or even mouse clicking another field, the msgbox captures the contents of the fiel and displays.

Now simply replace your code with my MsgBox calls, and the funciton will do the rest!

birkela

 
i am still hazy on what i need to do..

here is the code i am trying to execute (Cold fusion is involved)

<html>

<title>Untitled</title>
<script>

function getval() {

//--- i dont know how to write a function that will submit the form element 'nu'


}
</script>
</head>
<body>
<form name=fu>
<input name=&quot;nu&quot; onchange=&quot;getval()&quot;>
<!-- user will input a numeric value -->
</form

<!-- after form is submitted show value -->
<cfoutput>
<cfif isdefined (&quot;form.nu&quot;)>
the value of the form is #form.nu#
</cfif>
</cfoutput>



</body>
</html>
 
Hi macmac1

What birklea answered is correct.He explained it very clear.
If you want to catch the value of the field 'nu' every time the user changes its contents,you should use the 'onchange' event handler.
If you want to get the value of 'nu' every time the user click in other field,or press tab or enter,you should use the 'onblur' event handler.
Once you decided how you will manipulate the user's action,
you can get the value of 'nu' easily'

Here I assume you wish to get the value of 'nu' when the user enters in other field,just clicking on it,pressing tab or enter.If you wish the other case,just replace 'onblur' by 'onchange' in your form.

<html>
<title>Untitled</title>
<script language=&quot;javascript&quot;>
<!--
function getval()
{
fieldvalue=document.fu.nu.value;
document.getElementById('showvalue').innerText=The value of the field is '+fieldvalue;
}
//-->
</script>
</head>
<body>
<div align=&quot;center&quot;>
<form name=&quot;fu&quot;>
<input name=&quot;nu&quot; onblur=&quot;getval()&quot;>
<!-- user will input a numeric value -->
</form
<!---here you see the value of 'nu'-->
<hr>
<p id=&quot;showvalue&quot;>
This is the value of the field
</p>
<hr>
</div>
</body>
</html>

Please note that this will work on IE 5 and up and not NN,because 'innerText' property is not soported by NN.
You don't need to use CFML to display the value.

I hope this helps :)


alefusion
 
<script language = &quot;javascript&quot;>
function getVal()
{
alert(&quot;Tex Val is:&quot;+ window.document.frmtext.txtname.value);

</script>

<form name = &quot;frmtext&quot; >
<input type = text id = txtname name = txtname&quot; onblur= &quot;getVal()&quot;>

</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top