1

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

4
  • $("input[name=apply-code]").val();? Commented Oct 15, 2015 at 16:32
  • All you need : $("input[name="apply-code"]).val("New Text"). You can't change innerHtml for input types. Also, this would only work if you have name=apply-code unique to that field. Commented Oct 15, 2015 at 16:33
  • @DinoMyte Ok I will give it a go Commented Oct 15, 2015 at 16:33
  • @dwinnbrown one double inverted quote is missing after class please note that Commented Oct 15, 2015 at 16:41

3 Answers 3

1

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");

Sign up to request clarification or add additional context in comments.

3 Comments

This would change the text of all input controls having class wsite_form_input.
@DinoMyte there is a more specific class for the input that I can apply it to "wsite-coupon-input" so I think this should work
Please mark as answered if this answered your question.
1

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

Comments

0

Yes, it's possible, something like:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.