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

Saving values in text fields w/o submitting a form 1

Status
Not open for further replies.

iao

Programmer
Joined
Feb 23, 2001
Messages
111
Location
US
I have the following form (named TestForm.cfm):

<FORM ACTION=&quot;action_page.cfm&quot; METHOD=&quot;post&quot; NAME=&quot;theform&quot;>
Input name: <INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; VALUE=&quot;&quot;>
Input ID: <INPUT TYPE=&quot;text&quot; NAME=&quot;ID&quot; VALUE=&quot;&quot;>
<BR><BR>
<INPUT TYPE=&quot;button&quot; NAME=&quot;Add_ID&quot; VALUE=&quot;Add_ID&quot; onClick=&quot;window.location='TestForm.cfm'&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Submit_ID&quot; VALUE=&quot;Submit&quot;>
</FORM>

This is to allow the user to enter a name and an ID. Here is the problem. When the user enters a value in either of the text fields and then selects the &quot;Add_ID&quot; button, the text fields are cleared. I want these values to remain after selecting this button. I can do this if the button was a submit button (and or, if the form was submitted in any way). But, I don't know how to do this if all I am doing is redrawing the form. And that is the key. I need this to work without submitting the form.

Any ideas? Is it impossible?
 
<INPUT TYPE=&quot;button&quot; NAME=&quot;Add_ID&quot; VALUE=&quot;Add_ID&quot; onClick=&quot;window.location='TestForm.cfm?name=&quot;+document.theform.name.value+&quot;'&quot;>

and then
<INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; <cfif isdefined(&quot;name&quot;)>VALUE=<cfoutput>#name#</cfoutput></cfif>>
 
I don't know if I am doing something wrong, but everytime I try this, I get a javascript error: &quot;Unterminated string constant&quot;.

I checked and rechecked the line that is buggy:
<INPUT TYPE=&quot;button&quot; NAME=&quot;Add_ID&quot; VALUE=&quot;Add_ID&quot; onClick=&quot;window.location='TestForm.cfm?name=&quot;+document.theform.name.value+&quot;'&quot;>

Am I doing something wrong? The error occurs when I add the quotes between +document.theform.name.value+.

Obviously, if I leave the quotes out, then this string of text will appear when I click on the button.
 
of course - you have to escape the quotes; or else the browser reads : (say name.value is : my &quot;name&quot;)

<INPUT TYPE=&quot;button&quot; NAME=&quot;Add_ID&quot; VALUE=&quot;Add_ID&quot;
onClick=&quot;window.location='TestForm.cfm?name='my &quot;name&quot;'&quot;>
see : blue parts are not interpreted (as they are between quotes) but then it'll try to interpret &quot;name&quot; (in black) and crash

to escape quotes, you can use a reg exp (very elegant), or play with substr (i don't know any cross browser function that would escape quotes for you - in cf there are some, but they require to be SERVER side)
so :
<INPUT TYPE=&quot;button&quot; NAME=&quot;Add_ID&quot; VALUE=&quot;Add_ID&quot;
onClick=&quot;new_func()&quot;>

and in new_func, first retrieve the value for &quot;name&quot;, then parse it, then send it (window.location =...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top