0

I have this:

var swal = json.Event[i].SwURL;
$("#swurl").append("value='"+ swal +"'");

What I'm trying to achieve is to make the swal become the value in the form that I have. However it doesn't seem to be doing anything:

<input autofocus="autofocus" class="form-control" id="swurl"
       type="text" value="" name="event[swlink]">

This is the html:

Edit

Due to the nature of this potentially being a duplicate.

I've attempted this method

$("#swurl").val(swal);

However this hasn't worked.

Also I'm wondering if its because the javascript_tag is taking a while to load, Therefore not being inserted into the simple form.

Hers the simple form field if anyone was wondering

<div class="form-group">
  <%= f.label :swlink %>
  <div class="row">
    <div class="col-md-6">
      <%= f.text_field :swlink, :autofocus => true, class: "form-control", id: "swurl" %>
    </div>
  </div>
</div>
John Hascall
  • 9,176
  • 6
  • 48
  • 72
sam roberts
  • 217
  • 3
  • 12

2 Answers2

-3
$("#swurl").attr('value',swal);
$("#swurl").val(swal);

Should both work

Kasper Sølvstrøm
  • 270
  • 1
  • 2
  • 22
-3

What Praveen is providing is correct. But if you want particularly 'value' attribute to change. You can use below:

$("#swurl").attr('Value',swal);

Hope this will work for you.

kayess
  • 3,384
  • 9
  • 28
  • 45