user5030211
user5030211

Reputation:

How to show the output in textarea when using $('div') and CSS (JavaScript)

When I use this codes, it Prints the result in a new html page, how can I print the results in a nominated textarea? lets I want the result to be shown in: bookForm.myText.value

Update: PLEASE NOTE ONLY THE bTitle IS SUPPOSED TO BE ITALIC

HTML:

<div contenteditable="true"></div>

CSS:

span{
    font-style: italic;
}

JavaScript:

bTitle = bookForm.txtTitle.value;
bName = bookForm.txtName.value;
bNumber = bookForm.txtNumber.value;

var concatBook = "<span>"+bTitle+"</span> by "+bName+" sold "+bNumber+" Copies."
$('div').html(concatBook);

Upvotes: 0

Views: 283

Answers (2)

Dharmesh Goswami
Dharmesh Goswami

Reputation: 1265

Add Textarea in with id "mytext"

     <textarea id="mytext" name="somename"></textarea>

Add Javascript

      bTitle = bookForm.txtTitle.value;
      bName = bookForm.txtName.value;
      bNumber = bookForm.txtNumber.value;

      var concatBook = ""+bTitle+" by "+bName+" sold "+bNumber+" Copies.";
      $('#mytext').val(concatBook);  //this will display result in textarea
      $('#mytext').css('font-style', 'italic');

Upvotes: 3

Unni Babu
Unni Babu

Reputation: 1814

Step 1
Create a textarea with id, here id is "myTextarea"


    <textarea id="myTextarea" name="somename"></textarea>


Step 2
Javascript


    bTitle = bookForm.txtTitle.value;
    bName = bookForm.txtName.value;
    bNumber = bookForm.txtNumber.value;

    var concatBook = ""+bTitle+" by "+bName+" sold "+bNumber+" Copies.";
    $('#myTextarea').val(concatBook);  //this will display result in textarea

Upvotes: 0

Related Questions