Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Converting Client side Jquery to C# or something so it can be stored server side

asp.net code

<%@ Page Title="" Language="C#" MasterPageFile="~/ASPX/User.Master" AutoEventWireup="true" CodeBehind="MoodLog.aspx.cs" Inherits="INFT3970___Mood_Tracking.ASPX.MoodLog" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>jQuery UI Slider - Default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/> <link rel="stylesheet" href="/resources/demos/style.css"/> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script src="../JS/slider.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/> <link rel="stylesheet" href="/resources/demos/style.css"/> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<style> 
#slider .ui-slider-range 
{
    background: #369;

}
#slider2 .ui-slider-range 
{
    background: #369;

}
#slider3 .ui-slider-range 
{
    background: #369;

}
#slider4 .ui-slider-range 
{
    background: #369;

}
#slider5 .ui-slider-range 
{
    background: #369;

}

</style>

/asp:Content

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <form id="form1" runat="server"> <div id="mainContainer" style ="margin: auto; padding: 15px; width: 50%; height: auto; border: 1px solid black; background: rgba(255, 255, 255, 0.5); text-align: center;"> <br /> <h2> <b>How are you feeling today??</b> </h2>

<h3>Choose a mood that best suits how you felt today</h3>
<br />
<hr />
<!-- Slider 1 -->



<div id="happyDialog" title="Rate Your Happiness">

<h3>
    <b>How happy are you today?</b>
</h3>
<img src="../Pic/Happy.png" style="width:auto; height:auto;" />
<br />

<div id="slider" style="width: 50%; margin: auto; padding: 1px; border: 1px;"></div>

<div id="s2" style="background : silver; width: 50%; margin: auto; padding: 1px; border: 1px ">0%</div>

    <br />
    <hr />

<button id="happy">Submit</button>

</div>

<button id="happyOpener" style="background: rgba(255, 255, 255, 0.5); width: auto; height:auto; border-radius: 50%; border:10px solid #cfdcec; overflow:hidden;"><img src="../Pic/Happy.png" style="width:auto; height:auto;" /></button>


<!-- slider 2 -->


<div id="tiredDialog" title="Rate your tiredness">
<br />
<h3>
    <b>How tired are you?</b>
</h3>
<img src="../Pic/Sleepy.png" style="width:auto; height:auto;" />
<br />

<div id="slider2" style="width: 50%; margin: auto; padding: 1px; border: 1px;"></div>

<div id="s3" style="background : silver; width: 50%; margin: auto; padding: 1px; border: 1px ">0%</div>
    <br />
    <hr />
<button id="tired">Submit</button>
</div>

<button id="tiredOpener" style="background: rgba(255, 255, 255, 0.5); width: auto; height:auto; border-radius: 50%; border:10px solid #cfdcec; overflow:hidden;"><img src="../Pic/Sleepy.png" style="width:auto; height:auto;" /></button>

<!-- Slider 3 -->


<div id="confusedDialog" title="Rate your Confusion">
<br />
<h3>
    <b>Are you feeling confused?</b>
</h3>
<img src="../Pic/Confused.png" style="width:auto; height:auto;" />
<br />

<div id="slider3" style="width: 50%; margin: auto; padding: 1px; border: 1px;"></div>

<div id="s4" style="background : silver; width: 50%; margin: auto; padding: 1px; border: 1px ">0%</div>

        <br />
    <hr />
<button id="confused">Submit</button>

 </div>

<button id="confusedOpener"style="background: rgba(255, 255, 255, 0.5); width: auto; height:auto; border-radius: 50%; border:10px solid #cfdcec; overflow:hidden;"><img src="../Pic/Confused.png" style="width:auto; height:auto;" /></button>


<!--Slider 4-->


<div id="stressedDialog" title="Rate your Stress">
<h3>
    <b>Are you feeling stressed?</b>
</h3>
<img src="../Pic/Stressed.png" style="width:auto; height:auto;" />
<br />

<div id="slider4" style="width: 50%; margin: auto; padding: 1px; border: 1px;"></div>

<div id="s5" style="background : silver; width: 50%; margin: auto; padding: 1px; border: 1px ">0%</div>
        <br />
    <hr />
<button id="stressed">Submit</button>

<br />

</div>

<button id="stressedOpener" style="background: rgba(255, 255, 255, 0.5); width: auto; height:auto; border-radius: 50%; border:10px solid #cfdcec; overflow:hidden;"><img src="../Pic/Stressed.png" style="width:auto; height:auto;" /></button>



<!--Slider 5-->

<div id="angryDialog" title="Rate your Anger">

<h3>
    <b>Are you feeling Angry?</b>
</h3>
<img src="../Pic/Angry.png" style="width:auto; height:auto;" />
<br />

<div id="slider5" style="width: 50%; margin: auto; padding: 1px; border: 1px;"></div>

<div id="s6" style="background : silver; width: 50%; margin: auto; padding: 1px; border: 1px ">0%</div>
        <br />
    <hr />
<button id="angry">Submit</button>

</div>

<button id ="angryOpener" style="background: rgba(255, 255, 255, 0.5); width: auto; height:auto; border-radius: 50%; border:10px solid #cfdcec; overflow:hidden;"><img src="../Pic/Angry.png" style="width:auto; height:auto;" /></button>



<br />
<hr />

</div> <asp:HiddenField ID="hiddenType" Value ="s2" runat="server" /> <asp:HiddenField ID="hiddenPercentage" Value ="100" runat="server" />

</form> /asp:Content

Jquery Code

$(function () {

$("#slider").slider({

    max: 100,
    min: 0,
    change: function (event, ui) {

        var currentPercentageHappy = $("#s2").html(ui.value + "%");

    },
    step: 10,
    range: 'min',


});

$("#slider2").slider({

    max: 100,
    min: 0,
    change: function (event, ui) {

        var currentPercentageTired = $("#s3").html(ui.value + "%");
    },
    step: 10,
    range: 'min',


});


$("#slider3").slider({

    max: 100,
    min: 0,
    change: function (event, ui) {

        var currentPercentageConfused = $("#s4").html(ui.value + "%");
    },
    step: 10,
    range: 'min',


});

$("#slider4").slider({

    max: 100,
    min: 0,
    change: function (event, ui) {

        var currentPercentageStressed = $("#s5").html(ui.value + "%");
    },
    step: 10,
    range: 'min',


});

$("#slider5").slider({

    max: 100,
    min: 0,
    change: function (event, ui) {

        var currentPercentageAngry = $("#s6").html(ui.value + "%");
    },
    step: 10,
    range: 'min',


});

})

$(function () {

$("#happy").on("click", function () {
    window.alert($("#s2").text()),



    $("#happyDialog").dialog("close");

});

$("#tired").on("click", function () {
    window.alert($("#s3").text()),

    $("#tiredDialog").dialog("close");
});

$("#confused").on("click", function () {
    window.alert($("#s4").text()),

    $("#confusedDialog").dialog("close");
});

$("#stressed").on("click", function () {
    window.alert($("#s5").text()),

    $("#stressedDialog").dialog("close");
});

$("#angry").on("click", function () {
    window.alert($("#s6").text()),

    $("#angryDialog").dialog("close");
});

});

$(function () { //Happy Dialog $("#happyDialog").dialog({ autoOpen: false, show: { effect: "blind", duration: 1000 }, width: 600, height: 250, hide: { effect: "explode", duration: 1000 } }); //Happy Button opener $("#happyOpener").on("click", function () { $("#happyDialog").dialog("open"); });

//tired dialog
$("#tiredDialog").dialog({
    autoOpen: false,
    show: {
        effect: "blind",
        duration: 1000
    },
    width: 600,
    height: 250,
    hide: {
        effect: "explode",
        duration: 1000
    }
});
//tired button opener
$("#tiredOpener").on("click", function () {
    $("#tiredDialog").dialog("open");
});
// confused dialog
$("#confusedDialog").dialog({
    autoOpen: false,
    show: {
        effect: "blind",
        duration: 1000
    },
    width: 600,
    height: 250,
    hide: {
        effect: "explode",
        duration: 1000
    }
});
// confused opener
$("#confusedOpener").on("click", function () {
    $("#confusedDialog").dialog("open");
});
// stressed dialog
$("#stressedDialog").dialog({
    autoOpen: false,
    show: {
        effect: "blind",
        duration: 1000
    },
    width: 600,
    height: 250,
    hide: {
        effect: "explode",
        duration: 1000
    }
});
//stressed dialog opener
$("#stressedOpener").on("click", function () {
    $("#stressedDialog").dialog("open");
});
// angry dialog 
$("#angryDialog").dialog({
    autoOpen: false,
    show: {
        effect: "blind",
        duration: 1000
    },
    width: 600,
    height: 250,
    hide: {
        effect: "explode",
        duration: 1000
    }
});
//angry dialog opener
$("#angryOpener").on("click", function () {
    $("#angryDialog").dialog("open");
});

});

im really stressed out, basically the data cant be stored on a server because its all client side and i need to store the values of the slider in a database. super confused and im super worried im going to fail my degree if i cant get this to work

1 Answer

Steven Parker
Steven Parker
243,318 Points

Your have a lot of code there, all unformatted and difficult to read.

For something like this, it would be better to post a snapshot of a workspace.

But it sounds like you have the client-side complete, so now you need to implement the code-behind portion of the page to handle the submit postback and store your input.

Is this for Treehouse or somthing else? Regardless, didn't your studies include examples of creating the code-behind for handling server tasks?