eclipsis
eclipsis

Reputation: 1550

Insert nearby input's value in link using JS?

I have an input and a nearby link, and I would like to use JS to get the value from the input and insert it into the "mailto" element of the link. How can I accomplish this?

    '<input class="an-input" type="text" id="'+$.fn.dataTable.Editor.safeId(conf.id)+'">'+
    '<a class="ui-state-default inputButton an-button" href="mailto:">SEND</a>'

Upvotes: 0

Views: 63

Answers (3)

Arty9000
Arty9000

Reputation: 103

$input = $(".an-input");

$input.next(".an-button").attr("href", "mailto:" + $input.val());

Upvotes: 1

Gaurav Aggarwal
Gaurav Aggarwal

Reputation: 10177

Use this

jQuery(function($){
  var inputVal = $('input').val();
  $('a').attr('href','mailto:'+ inputVal);
})

Upvotes: 1

Victor Levin
Victor Levin

Reputation: 1177

jQuery(function($){

   $('.an-button').click(function(e){

      $(this).attr('href', 'mailto:'+$('.an-input').val());

   }

});

Upvotes: 1

Related Questions