dwinnbrown
dwinnbrown

Reputation: 4009

Javascript - Changing content for input element which has no value

So I am working with Weebly as a CMS for one of my clients. I am having to change the content for an input field however by default it has no value. The code for the input is as follows

<input class="wsite-form-input name="apply-code" placeholder="Enter Code">

I am trying to change the content of this with some JavaScript but not sure about the best way to go about this. I would normally just create a variable and then change the value of that variable but seeing as there isn't one present I don't think I can do it.

Could I change the inner text?

Thanks

Upvotes: 1

Views: 50

Answers (3)

Himesh Aadeshara
Himesh Aadeshara

Reputation: 2121

you can easily change the input element's value as like this

var name="Put your name here";
$('input.wsite-form-input').val(name);

here is demo work

Upvotes: 1

Vitor Paiva
Vitor Paiva

Reputation: 56

Yes, it's possible, something like:

function changeInputValue(textValue){
 document.getElementsByName("apply-code")[0].value=textValue;
 }

Upvotes: 0

Jeroen Bellemans
Jeroen Bellemans

Reputation: 2035

First of all, you are missing a closing apostroph after .wsite-form-input, and to give it a value, you could do the following:

$(".wsite-form-input").val("Your value here");

Upvotes: 1

Related Questions