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

I am trying to write a JScript to work with CF

Status
Not open for further replies.

CalvinR

ISP
Joined
Nov 21, 2003
Messages
1
Location
US
Hi all,

I am having trouble trying to figure out this prob..

I am trying to write a function that will submit one form element? I am trying to pass that value to a conditional statement. I do not want the entire form to submit its self. I want to keep that information on the same page. See the code below..it my better explain my sit.

Thanks
CalvinClick



<html>

<title>Untitled</title>
<script>

function geval() {

//--- 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>
 
Not sure why you're tyring to do this, but you must know that by the time the page is rendered by the user's browser, all ColdFusion processing has already taken place. Therefore, you cannot use a form field value in a CF statement on the same page. Not even with JS or VBS.

That being said, you could submit the form back to itself to display the value of that form element. In other words, make the ACTION attribute of the FORM tag the same as the current page and submit the page back to itsef.
Code:
<!--- This page is saved as myPage.cfm ---> 
<CFPARAM NAME=&quot;myValue&quot; DEFAULT=&quot;&quot;>

<BODY>
<FORM ACTION=&quot;myPage.cfm&quot; METHOD=&quot;post&quot;>
   <INPUT TYPE=&quot;text&quot; NAME=&quot;myText&quot;>
   <INPUT TYPE=&quot;submit&quot;>
</FORM>

<CFOUTPUT>
   <CFIF myValue IS &quot;&quot;>
      You haven't submitted anything yet.
   <CFELSE>
      You submitted: #myValue#
   </CFIF>
</CFOUTPUT>
</BODY>
Kevin
slanek@ssd.fsi.com

&quot;Life is what happens to you while you're busy making other plans.&quot;
- John Lennon
 
Here is another idea,

Put the form variable of interest (nu) in a form of its own. If you have several variables and you only want to submit the variable that is changed, put each one in a separate form. Name each form with a unique name (unique on that page). (If you need a submit button for the entire page, put it in its own form as well.)

<form name=&quot;nu_form&quot; action=&quot;some_template.cfm?var=nu&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;nu&quot; value=&quot;#queryname.nu#&quot; onChange=&quot;this.form.submit();&quot;>
</form

In this scenario, some_template.cfm know that you're sending it the variable &quot;nu&quot; and does the appropriate thing. As it turns out, you don't need a name on each form. However, if you want to validate the data entered before submitting, you could use the example above, except that you would write something like onChange=&quot;return validate_form(this.form);&quot;. the function would go somethin like this:

function validate_form(f) {
switch (f.name) {
case 'nu_form': // this is probably not correct syntax; don't have time to look it up
//here you place validation code. if invalid return false; else f.submit()
}
}

Don't overlook the possibility of setting the 'location' (i.e., invoking a URL with the parameters that you specify, such as the value of nu)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top