Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

adding some classic .asp code to javascript

Posted on 2014-04-02
9
Medium Priority
?
572 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 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39973626
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
ID: 39973657
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 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39973676
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Mark Wood
ID: 39973849
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
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39974091
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
ID: 39978014
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 34

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 39980294
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
ID: 39987411
Thanks for the help
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

927 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