0

For some reason clicking the button will not but the variable in the textbox, I'm not getting any syntax errors in my compiler so I think it's a logic error. THanks in advance

JS:

var testvar = 5
$('.teambtn').click(function() {
document.getElementById('team').text = (testvar);
});

html:

<textarea id=team cols="50" rows="10">
Your Team Will be here:
</textarea>


            <button type="button" id=teambtn class="btn">Export</button>
1
  • I also tried without the parentheses around 'testvar' so that's not the problem Commented Feb 9, 2015 at 1:45

3 Answers 3

1

I think you're almost there. You just need to remove the brackets from test var and instead of replacing the .text property, you need to replace the .value property

document.getElementById('team').value = testvar;

Check out this link because I think it accomplishes what you want, http://www.mediacollege.com/internet/javascript/form/add-text.html

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

Comments

0

i think the problem is below .

$('.teambtn')

try to use $('#teambtn') .

Because you declared it is an id . But the selector indicates to class .

If you do not want to change the .js code then you can add it as a class .

I hope this will helps you .

Comments

0

Since you have used jQuery, below is sample usage:

var testvar = 5
$('#teambtn').click(function() {
   $('#team').val(testvar);//set the value of textarea
});

teambtn and team are ids given, so to fetch by id using jQuery's selector #

To get/set the value of textarea and input elements use jQuery's $.val()

EDIT

Problem with your code is that you are trying to set text property of textarea, which is not valid instead you must try using value attribute:

document.getElementById('team').value = testvar;

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.