Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. How to trigger on change on a HTML5 var tag?

How to trigger on change on a HTML5 var tag?

Scheduled Pinned Locked Moved Web Development
htmldatabasetutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nicky Tse
    wrote on last edited by
    #1

    <input id="rdo1" type="radio" name="rdoTest" value="Hello" />
    <input id="rdo2" type="radio" name="rdoTest" value="World" />
    Test Value

    $(document).ready(function () {
    $('[name=rdoTest]').change(function () {
    $('#test1').text($('[name=rdoTest]:checked').val());
    });

    $('#test1').change(function () {
        alert($('#test1').text());
    });
    

    });

    My code here but nothing happened

    Richard DeemingR 1 Reply Last reply
    0
    • N Nicky Tse

      <input id="rdo1" type="radio" name="rdoTest" value="Hello" />
      <input id="rdo2" type="radio" name="rdoTest" value="World" />
      Test Value

      $(document).ready(function () {
      $('[name=rdoTest]').change(function () {
      $('#test1').text($('[name=rdoTest]:checked').val());
      });

      $('#test1').change(function () {
          alert($('#test1').text());
      });
      

      });

      My code here but nothing happened

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      The <var> element doesn't seem to raise the change event on its own. You'll need to trigger it manually:

      $('#test1').text($('[name=rdoTest]:checked').val()).change();


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      N 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        The <var> element doesn't seem to raise the change event on its own. You'll need to trigger it manually:

        $('#test1').text($('[name=rdoTest]:checked').val()).change();


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        N Offline
        N Offline
        Nicky Tse
        wrote on last edited by
        #3

        But

        raise the event on click or mouseover

        Richard DeemingR 1 Reply Last reply
        0
        • N Nicky Tse

          But

          raise the event on click or mouseover

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Yes, but it doesn't raise the change event.

          change - Event reference | MDN[^]:

          The change event is fired for <input>, <select>, and <textarea> elements when a change to the element's value is committed by the user.

          <var> is not one of the elements that fires the change event.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups