Solved

adding some classic .asp code to javascript

Posted on 2014-04-02
9
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 53

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 53

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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 53

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 33

Accepted Solution

by:
Big Monty earned 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

738 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