Link to home
Start Free TrialLog in
Avatar of Mark Wood
Mark WoodFlag for United States of America

asked on

adding some classic .asp code to javascript

i have a javascript slider that I want to add some classic asp to in order to control size etc.

example:
slider1.$SetScaleWidth(Math.min(parentWidth, 1040 ));

I want to be able to do the following or something similar:
slider1.$SetScaleWidth(Math.min(parentWidth, <%=rs(width")%> ));

any help will be appreciated
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

What is the problem.  What you have is correct.  However, keep in mind javascript runs AFTER the page loads and asp runs on the server BEFORE the page loads.  

Also you have <%=rs(width")%>  and it should be <%=rs("width")%> (missing quote)
Avatar of Mark Wood

ASKER

if I have it like this the slider stops working:

slider1.$SetScaleWidth(Math.min(parentWidth, <%=rs("width")%> ));

if I have it like this the slider will work but it isn't pulling the value from the db:
slider1.$SetScaleWidth(Math.min(parentWidth, '<%=rs(width")%>' ));
You just added a complete new variable with single quotes.

slider1.$SetScaleWidth(Math.min(parentWidth, <%=rs("width")%> ));

if I have it like this the slider will work but it isn't pulling the value from the db:
slider1.$SetScaleWidth(Math.min(parentWidth, '<%=rs(width")%>' ));


IF it worked without single quotes, why are you adding?  My comment was about the double quotes missing for the field name, width.

Try no single quotes and double quotes for the field name.  Also, view source and make sure there is actual data for  <%=rs("width")%>  
slider1.$SetScaleWidth(Math.min(parentWidth, <%=rs("width")%> ));

Open in new window

I understand that .. what I am saying is it isn't pulling the data for the size when using slider1.$SetScaleWidth(Math.min(parentWidth, <%=rs("width")%> )); and the slider stops working.
Does this work?
slider1.$SetScaleWidth(Math.min(parentWidth, 1040 ));

Open in new window

If it does, check if this works
slider1.$SetScaleWidth(Math.min(parentWidth, <%="1040"%> ));

Open in new window

If that works, see if this works
<%
dim myWidth
myWidth="1040"
%>
slider1.$SetScaleWidth(Math.min(parentWidth, <%=myWidth%> ));

Open in new window

If all this works and the below does not, then you need to check that there is data in the rs("width")
slider1.$SetScaleWidth(Math.min(parentWidth, <%=rs("width")%> ));

Open in new window

One way you can do this is add the code just before the js you have and write out the width and add a response.end.  This will render the page and end it just after it spits out the width.  
response.write "The width is set to: "& rs("width")
response.end

Open in new window

It is possible the data looks good visually, but may have a character you can't see or space. Try this.
if not isnull(rs("width")) then
     if isnumeric(rs("width") then
         response.write "The width is set to: "& rs("width")
         else
         response.write "There is data in the width, but it is not numeric"
     end if
    else
    response.write "The field is null"
end if
response.end

Open in new window



Is this the sample you are working off of? https://github.com/jssor/slider.js/blob/master/themes-jquery/image-slider.source.html
function ScaleSlider() {
                var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
                if (parentWidth)
                    jssor_slider1.$SetScaleWidth(Math.min(parentWidth, 600));
                else
                    window.setTimeout(ScaleSlider, 30);
            }

Open in new window

If it is, why are you trying to set the width dynamically.  If you have 10 images listed, they are all going to be the same size or at least in the same size container. Unless for every page refresh (request.querystring or request.form) you are using a different layout that requires the parent to use a different width for the set of images, I think this should be static.

If I have this wrong, your next step here should be to render your html (run the page so it is working), view source, then paste that code here so we can see how you are using it.  Then let us know which parts should be dynamic and how you are getting the data.
I think rs("width") is not returning the value that you are expecting. Perhaps you have some issue with the code used to retrieve data. Open your page in a web browser, right click and then select View Page Source. In the page source, look at your javascript line and you will see the issue.

I repeat it again that most probably rs("width") is not returning the value that you are expecting.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help