Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get input data without refreshing data with AJAX?

I have a form. It is include two radio button and one input. Radio buttons are name hexadecimal to decimal and decimal to hexadecimal.

When I write text to input I need to show result without page refreshing.

For example 1 result -> 10 12 result->23 directly showing.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So I make a research I need to use AJAX inside PHP. But all examples working click button. I don’t want to use button.

Can you give me a example post request same page in AJAX ?

>Solution :

Consider the following jQuery example.

$(function() {
  $("#input").keyup(function(event) {
    var input = $(this).val();
    if ($("#dec").is(":checked")) {
      $("#output").val(parseInt(input).toString(16));
    } else {
      $("#output").val(parseInt(input, 16));
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="myForm">
  <div>
    <input type="text" id="input" value="0" />
  </div>
  <div>
    <input type="radio" value="decToHex" name="select" id="dec" checked="true" />
    <label for="dec">Decimal to Hex</label>
  </div>
  <div>
    <input type="radio" value="hexToDec" name="select" id="hex" />
    <label for="hex">Hex to Decimal</label>
  </div>
  <div>
    <input type="text" id="output" value="0" />
  </div>
</form>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading