0

I need help with my function. I dont know how to set right text into val() function.
I have form, where I write text which I want to passing via val

<form>
    <input type="text" id="formValueId" name="valueId"/>
    <input type="button" id="theButton" value="Send"/>
</form>

And here is the javascript:

var button = document.getElementById("theButton"),
value =  button.form.valueId.value;
button.onclick = function() {
    $("#modal").fadeOut(400, function() {
    $("#bg").fadeOut(400, function() {
      $theTarget.val("My inserted text should be here"); //Before here were (value)
    });
  });
}

It's continue of this - jQuery selector - inserting value only to selected id Thanks

David
  • 35
  • 8
  • 1
    Possible duplicate of [Set Value of Input Using Javascript Function](https://stackoverflow.com/questions/5700471/set-value-of-input-using-javascript-function) – Striped Mar 12 '18 at 08:07
  • 1
    What is `$theTarget` variable? – Eddie Mar 12 '18 at 08:08
  • @Eddie $theTarget = $(this); – David Mar 12 '18 at 08:11
  • What are you trying to achieve exactly? – Eddie Mar 12 '18 at 08:13
  • I edit end of my question - I add link, where you can find function before adding input :) – David Mar 12 '18 at 08:16
  • What do you expect when the btn is clicked? – Eddie Mar 12 '18 at 08:18
  • I have many INPUTS. When I click into input it will open this form in modal window. I write text into input, click submit. And wrote text will insert into clicked INPUT. – David Mar 12 '18 at 08:21
  • You can close this thread - After two hours of googling I found my answer here - https://stackoverflow.com/questions/5896287/jquery-passing-value-from-one-input-to-another – David Mar 12 '18 at 09:21
  • For others I changed only this row - $theTarget.val($('#formValueId').val()); – David Mar 12 '18 at 09:30

0 Answers0