javascript - How to get text value from radio button and assign value to a specific div -


if using 1 text box , 3 div, how can set entered value in div? here code. have div value radio button selected. likewise, how can text box value?

here code.

<form id="myform"> <div>choose option:</div> <div> <input type="radio" name="user_options" value="456"/> </div> <div name="deff" id="val1" x>123</div> <span>css</span> <br></br> <div> <input type="radio" name="user_options" value="456" />  </div> <div name="deff" id="val2" >456</div> <span>html</span> <br></br> <div> <input type="radio" name="user_options" value="678" />  </div> <div name="deff" id="val3" >678</div> <span>jquery</span> <br></br>  <div name="deff" id="val4" >     <input type="radio" name="user_options" value="675" /> </div>     <input class="text-input" id="other-input" size="5" value=""> <span>js</span> <br></br>   <div><button id="radio_submit" type="button">show selected radio</button></div> </form> <div id="valueee"></div>   <script>     $(document).ready(function() {         $("#radio_submit").click(function (e) {          var check = $("input[name=user_options]:checked").parent().next().text();          if(!check){               alert('please select options!');          }else{               $('#valueee').html(check);            }         });     }); </script> 

jsfiddle

not sure meaning may need again check , try val() if undefined,

view demo jsfiddle

$(document).ready(function () {      $("#radio_submit").click(function (e) {          var check = $("input[name=user_options]:checked").parent().next().text();          if (!check) var check = $("input[name=user_options]:checked").parent().next().val();          if (!check) {              alert('please select options!');          } else {              $('#valueee').html(check);          }      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  <form id="myform">      <div>choose option:</div>      <div>          <input type="radio" name="user_options" value="456" />      </div>      <div name="deff" id="val1" x>123</div>      <span>css</span>        <br></br>      <div>          <input type="radio" name="user_options" value="456" />      </div>      <div name="deff" id="val2">456</div>      <span>html</span>        <br></br>      <div>          <input type="radio" name="user_options" value="678" />      </div>      <div name="deff" id="val3">678</div>      <span>jquery</span>        <br></br>      <div name="deff" id="val4">          <input type="radio" name="user_options" value="675" />      </div>      <input class="text-input" id="other-input" size="5" value="" />      <span>js</span>        <br></br>      <div>          <button id="radio_submit" type="button">show selected radio</button>      </div>  </form>  <div id="valueee"></div>


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -