jquery - Cannot get text value of a clicked link -


i'm trying text value of clicked link, keeps being displayed id value.

i searched web , believe using correct method. tried 1 "target.text".

can please inform me have wrong following jsfiddle?

html

<form name="form" id="form" action="" method="post">     <input type="text" id="startdate">     <input type="text" id="enddate">     <input type="hidden" id="id" value="0">     <input type="hidden" id="idtext" value="">     <button type="submit" value "change" name="change">change</button>     <br> <a href="1">palprd</a>      <br> <a href="3">paltst</a>      <br> <a href="2">eyebal</a>      <br>     <br>     <button type="submit" value "back" name="back">back</button> </form> 

js

$('a').click(function (event) {     event.preventdefault();      var url = $(this).attr('href');     $("#id").val(url);      var text = $(this).text();     $("#idtext").text();      //var hv = $('#id').val();     var hv2 = $('#idtext').val();      //alert(hv);     alert(hv2);      $('#form').submit();     return false; });  

please feel free edit jsfiddle...

js fiddle

you forgot load jquery in fiddle , needed change

$("#idtext").val(text);

 $('a').click(function(event) {     event.preventdefault();       var url = $(this).attr('href');     $("#id").val(url);       var text = $(this).text();     $("#idtext").val(text);         $('#form').submit();     return false;   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <form name="form" id="form" action="" method="post">    <input type="text" id="startdate">    <input type="text" id="enddate">    <input type="hidden" id="id" value="0">    <input type="hidden" id="idtext" value="">    <button type="submit" value "change" name="change">change</button>    <br> <a href="1">palprd</a>      <br> <a href="3">paltst</a>      <br> <a href="2">eyebal</a>      <br>    <br>    <button type="submit" value "back" name="back">back</button>  </form>

and here clean fiddle


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -