Placing ASP Code Within Javascript

liunx

Guest
Is it possible to do so? I have a Javascript menu that has it's cell colours set as variables. I would like to change the javascript variable into an ASP variable, since I want to place the value in a database and change the colour through a form.

For now, we have:

var LowBgColor='#000080';

but I would like to have:

var LowBgColor='#<% objRS %>';

Where the objRS is the SQl statement pulling the colour from the database.

Is it at all possible to use ASP within Javascript, or is it limited to use only within HTML? And if so, are there any suggestions about how I can accomplish my task? Thanks in advance.You have almost got it:


var LowBgColor='#<%= objRS %>';


'=' is shorthand to response.writeNot so fast rdove. that is an object they are going to need the syntax to get the field out also..

<%= rsObj("FieldName").Value %>Yea..I figure it was an object, but to be on the safe side I used similiar syntax in my answer. The post isn't clear if he is forming a recordset or if objRS is the value of a variable containing the information.That did the trick fellas, thanks!

I have another question, but I'll start a new thread for it.This was very useful. Can we do the reverse of it? I am looking for exactly opposite to it and its not working for me. I am working on double dropdown menu. when we select something from first dropdown menu, I want to capture the selection (I am able to do that) and then use it in the SQL query where clause (not able to do that) for populating the second dropdown menu on the same page.

onChange="populate(document.form1.select1.value);


function populate(xInt)
{
alert(xInt);
init();
if (!optionTest) return;
alert('came here1');

var BrCust=new Array(" & rset2("Cnt") & ");
var BrID=new Array(" & rset2("Cnt") & ");
var BrT=new Array(" & rset2("Cnt") & ");

xLen=0;
for ( i=0; i < BrCust.length ; i++){
if (xInt == BrCust){
box2.options[xLen+1]= new Option(BrT,BrID);
xLen++
}
}
}

I need rset2 setup with a query:

strsql2 = "select * from customer where customer_num = <value selected in the first dropdown menu>"
set rset2 = oConn.Execute(strsql2)

Basically, I am looking for something like: how to assign a variable in asp from javascript.

Thanks. I am breaking my head here for this but not getting it work..Yea..I figure it was an object, but to be on the safe side I used similiar syntax in my answer. The post isn't clear if he is forming a recordset or if objRS is the value of a variable containing the information.

its very clear. In every professional peice of code that you open that doesn't have that type of camel case hugarian notation then you are working in the wrong place.
 
Back
Top