Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Natasha 79 posts 195 karma points
    Jan 22, 2016 @ 17:10
    Natasha
    0

    Razor and Jquery select

    Hi there

    This is making me dizzy!

    I am trying to use jquery so that when a user selects said value the list is sorted by that value, but my Syntax is wrong and whatever I try doesn't work. Please help!

    This is my code:

        Order by:
        <select id="myselect">
      <option value="title">Title</option>
      <option value="Last   Updated">Last Updated</option>
      <option value="Themes">Themes</option>
      </select>
    
    
    <script type="text/javascript"> 
    $(document).change(function() {
      if ($("#mySelect").val() == "Title") {
          var selection = Model.Children.OrderBy("id desc");}
        if ($("#mySelect").val() == "Title") {
          var selection = Model.Children.OrderBy("lastUpdated");}
    
    
    });
    </script>
    

    Thanks in advance Natasha

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Jan 23, 2016 @ 12:25
    Alex Skrypnyk
    0

    Hi Natasha,

    Maybe you need selector like that :

    <script type="text/javascript"> 
    $('#mySelect').change(function() {
      if ($("#mySelect").val() == "Title") {
          var selection = Model.Children.OrderBy("id desc");}
        if ($("#mySelect").val() == "Title") {
          var selection = Model.Children.OrderBy("lastUpdated");}
    
    
    });
    </script>
    

    Thanks,

    Alex

  • Bijesh Tank 192 posts 420 karma points
    Jan 25, 2016 @ 09:51
    Bijesh Tank
    0

    Hi Natasha

    I would also take a look at your casing of id's and values as this can prevent your JS from running.

    e.g.

     Order by:
    <select id="mySelect">
      <option value="title">Title</option>
      <option value="lastupdated">Last Updated</option>
      <option value="themes">Themes</option>
    </select>
    
    $('#mySelect').change(function() {
      if ($("#mySelect").val() == "title") {
    ........
    

    /B.

  • Natasha 79 posts 195 karma points
    Jan 27, 2016 @ 16:45
    Natasha
    0

    This hasn't worked I think because my content is in a table so I'm going to have to use a different approach - using a datatable, but thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft