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

How to assign a database field to a JavaScript variable?!

Status
Not open for further replies.

midnightcafe

Programmer
Nov 22, 2000
1
AE
Hi Reader ...
I need to retrieve a field called MyMessage from a database and assign it to a JavaScript variable. So, can you help me doing this. To explain more, I tried to write the following code:

<!--- Start code --->

<CFQUERY Datasource=&quot;DSN&quot; Name=&quot;Q1&quot;>
Select MyMessage From Messages
</CFQUERY>

<CFOUTPUT Query=&quot;Q1&quot;>

<Script Language=&quot;JavaScript&quot;>

var messages=new Array();
messages[0]='#MyMessage#';

</Script>

</CFOUTPUT>

<!--- End of code --->
 
just put the var messages=new Array(); OUTSIDE of the cfoutput, and use a counter instead of always replacing the first value of the array
because what you're doing is that for each new row : first you EMPTY the message array, then you set the first value of the array equal to mymessage

try this instead :
<Script Language=&quot;JavaScript&quot;>
var messages=new Array();
<CFOUTPUT Query=&quot;Q1&quot;>
messages[#CurrentRow#]='#MyMessage#';
</CFOUTPUT>
</Script>

if it doesn't work, this sure does :

<Script Language=&quot;JavaScript&quot;>
var messages=new Array();
function update_my_array(value, index) {
messages[index]=value
}
<CFOUTPUT Query=&quot;Q1&quot;>
update_my_array('#MyMessage#', #CurrentRow#)
</CFOUTPUT>
</script>







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top