How to set a value present in anchor tag to a hidden field upon clicking on the hyperlink text(i.e. value present in anchor tag)?

I'm haiving following code:

<a class="que_issue" href="#">
      QUE38552
</a>

Now I want to set the value 38552(only question id and not the string QUE) to the following hidden field:

<input type="hidden" name="question_id" id="question_id" value=""/>

Also note that the page shouldn't be redirected to another location as I'm showing the pop-up dialog on the click of above hyperlink. The script to show the pop-up dialog is working fine, no issue with that. There are many such hyperlinks containing different question ids(like QUE38552) are present on the same page. I want to set the value of hidden field of only that question id on which user has clicked. This hidden field is present on the diaolg pop-up which I'm going to show. Can anyone plese help me in this regard? Thanks in advance.

Answers


Try,

$('.que_issue').click(function(e){
 e.preventDefault();
 $('#question_id').val($.trim($(this).text()).substring(3));
});
DEMO

You can do:

$('.que_issue').click(function() {
    var number = $(this).text().match(/[0-9]+/g);
    $('#question_id').val(number);
});

Fiddle Demo


Need Your Help

Getting a Java SecurityException while starting an activity

java android exception android-permissions

I am facing this weird situation where I am getting the below logs.

Xcode storyboard seque loops back to the same view

xcode loops view error-handling storyboard

I am using storyboard seques to change views to other parts of my app but when I linked my main view to the next and called for the seque in the function within my enter button it just loops back t...