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!

Database will not expand variable.

Status
Not open for further replies.

Lotruth

Programmer
May 2, 2001
133
0
0
US
I am trying to create a script that updates an Access database each time a person enters data into a text field by using the onblur function. Here is my code:

<html>
<head>
</head>
<body>
<script language=&quot;javascript&quot;>
function test(var) {
<cfquery datasource=&quot;help&quot; name=&quot;A&quot;>
update employees
set name='var'
where id=1
</cfquery>;
window.alert('This field has been saved');
}
</script>

<input type=&quot;text&quot; name=&quot;system&quot; value=&quot;Carlos&quot; onblur=&quot;test('Carlos')&quot;>
</body>
</html>

Instead of entering Carlos into the database, it enters var. What am I doing wrong.
 
You don't need the single quotes around :

set name='var'

should be :

set name=var Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Actually, I would imagine Access will need the quotes but they will need to be built into the variable:

var = &quot;\'&quot; + var + &quot;\'&quot;

The way you're doing it now, you're sending the string literal var to the database, not the variable var.
 
Thanks. I tried both of your suggestions with no success.
The problem seems to be that if I add pound signs around the variable in the sql statement, then the javascript function cant understand it. If I dont, then the cfquery tag reads the variable literally. Is there anything else that I could try?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top