2
<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  <style type="text/css">
    #slider { margin: 10px; }
  </style>
 <input type="text" value="" id="rateToPost"/>
<script type="text/javascript">
     var my = document.getElementById("rateToPost").onchange();
     alert(my);
</script>
  <div style="width:75px;height:48px;">
  <div style="width: 5px;margin-left: 10px;">1</div>
  <div style="width: 5px;margin-left: 38px;margin-top: -10px;">2</div>
  <div style="width: 5px;margin-left: 70px;margin-top: -13px;">3</div>
  <div style="width: 5px;margin-left: 98px;margin-top: -12px;">4</div>
  <div style="width: 5px;margin-left: 124px;margin-top: -12px;">5</div>
  </div>

  <script>
  $(document).ready(function() {
    $("#slider").slider({
                range: "min",
                value: 2,
                min: 1,
                max: 5,
    //this gets a live reading of the value and prints it on the page
                slide: function( event, ui ) {
                    $( "#ratingResult" ).text( ui.value );
                },
//this updates the value of your hidden field when user stops dragging
            change: function(event, ui) { 
                $('#rateToPost').attr('value', ui.value);
            }});
  });
  </script>

</head>
<body style="font-size:62.5%;">
<div id="slider"></div>
</body>
</html>

In the above script I used a slider for rating. But what is the problem here is I have to fetch the text box value onchange and highlight the corresponding rating number background. But I cant fetch the value. Anyone can help to solve thisproblem. Thanks in advance

4 Answers 4

8

Try this using jQuery:

$('#rateToPost').on("change", function () {
  alert($(this).val());
});
Sign up to request clarification or add additional context in comments.

1 Comment

Can't fetch the value using the jquery function
3

Since $('#rateToPost') is a form element: Use the val() method.

Comments

1
 $('#rateToPost').keyup(function(){
       $('#slider').slider({value: this.value});
    });

Demo http://jsbin.com/azosab/2/edit

2 Comments

<script type="text/javascript"> var my = document.getElementById("rateToPost").onchange(); alert(my); </script> Do you note this one. The var "my" is getting the value. But it didn't alert the value of variable "my"
here, you need to add document.ready on that script jsbin.com/azosab/6/edit
1

assign value:

$('#rateToPost').val(ui.value);

read value:

var res = $('#rateToPost').val();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.