Solved

adding some classic .asp code to javascript

Posted on 2014-04-02
9
521 Views
Last Modified: 2014-04-08
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
0
Comment
Question by:Mark Wood
9 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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)
0
 
LVL 2

Author Comment

by:Mark Wood
Comment Utility
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")%>' ));
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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

0
 
LVL 2

Author Comment

by:Mark Wood
Comment Utility
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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.
0
 
LVL 13

Expert Comment

by:devlab2012
Comment Utility
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.
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
Comment Utility
I would create an asp variable,  store the value from rs ("width") in it,  make sure there it is a valid numerical value, then right it out to the JavaScript function:

widthVal = rs("width")
If not isNumeric( widthVal ) then widthVal = 1040 '-- this can be any default value you want to set

Then in your JavaScript code you can do:

slider1.$SetScaleWidth(Math.min(parentWidth, <%=widthVal%> ));

This'll ensure you'll always have valid syntax in place. I agree with the other posters that the data you're getting back is probably incorrect,  but at least using this method you won't break the script
0
 
LVL 2

Author Closing Comment

by:Mark Wood
Comment Utility
Thanks for the help
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now