javascript - Please use POST resquest when sending form with JS -


what i'm missing here print 'user_input' display paragraph ?

is myform.submit required? because can access variable , make alert it..

<script language="javascript">     function getdata(input) {         var input = document.getelementbyid("user_input").value;         // alert(input)         document.myform.submit()         $('.display').text("the url : " + input)         }   </script>    <script   src="https://code.jquery.com/jquery-3.2.1.slim.js"   integrity="sha256-ta8y0xqiwnpwmoil3sgacfl2rvxhja8qp0+1ucgmrmg="   crossorigin="anonymous"></script>  <form id="myform"> <label><b>enter url</b></label> <input type="text" name="message" id="user_input"> <input type="submit" id="submit" onclick="getdata()"><br/> <p id="display"><span></span></p> </form> 

don't mix java-script/jquery each-other.

since using jquery library in better way below:-

working example:-

$(document).ready(function(){ // when document rendered    $('#submit').click(function(e){ // on click of submit button      e.preventdefault(); // prevent form submit      var input =$("#user_input").val(); // input value      $('#display').text("the url : " + input); // add text paragraph    });  });
<script src="https://code.jquery.com/jquery-3.2.1.slim.js" integrity="sha256-ta8y0xqiwnpwmoil3sgacfl2rvxhja8qp0+1ucgmrmg=" crossorigin="anonymous"></script>    <form id="myform">    <label><b>enter url</b></label>    <input type="text" name="message" id="user_input">    <input type="submit" id="submit"><br/><!-- no need of onclick-->    <p id="display"><span></span></p>  </form>


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -