This is an archived thread from the StopByte developer forum —
browse all archived threads.
StopByte is now a payments & ecommerce toolkit — check out our
free calculators.
I want to have the slider I have already coded, and then make it print the output. For example, if you slide the slider to 45, it will print 45. This is what I have -
Why the extra < > symbols? And where is the "print2" element?!
2 Likes
Yassine
(Yassine)
#3
Hi @Nathan_Chan As @sam explained, You have many syntax errors, undefined elements and logic mistakes.
Some Mistakes:
You are calling this method, on load to add couple handlers to the page which is good, but keep in mind two main things:
The element #percentage is never defined because the script is executed before the window is constructed. and it’s a JQuery code!
You are defining the sliderValue variable, within the event handlers but then setting the print2 value outside the event handlers which is not correct.
print2 is never defined!
$(function () {
$("#percentage").on("slidestop", function () {
sliderValue = $(this).val();
})
$("#percentage").on("change", function () {
sliderValue = $(this).val();
})
});
This should be done inside the event handlers (of course after correcting the syntax and defining print2)
First call your initialization code inside window.onload (to make sure all elements are defined):
This is the event handler when the slider value changes…
Second define your print2 element, for this example I created a little label for that:
Hope that helps @Nathan_Chan, And please make sure to mark this post as answer if it does answer your question otherwise you can freely discuss it in here and we will all be happy to assist as we can
Best of luck.
2 Likes
isoftech
(isoftech)
#4
@Yassine Boom full answer I was about writing a little answer for @Nathan_Chan here but then saw yours and I feel like you done all the work for us already
no wonder you’re the leader here, I’m really proud of you, and thanks for all the effort you are making to help everyone