Namrata Shrivas
Namrata Shrivas

Reputation: 77

How to give space or next line feature in javascript?

Here is my java script code:

function for_approve(){
var approve = confirm(format_stock_id.length + 
               "&nbsp;Stock Record(s) is selected for approval.<br /> 
               Do You Want to send it for Approval");

}

It gives me result as:

3 &nbsp;Stock Record(s) is selected for approval.<br />Do You Want to send it for Approval

What should i do for space and new line.

Upvotes: 0

Views: 4371

Answers (6)

Sharikov Vladislav
Sharikov Vladislav

Reputation: 7269

Use the \n symbol:

function for_approve(){
  var approve = confirm(format_stock_id.length + 
               " Stock Record(s) is selected for approval.\n 
               Do You Want to send it for Approval");

}

You can check this right here. Open console in your browser and write: alert("bob\nbob");

EXAMPLE

Command:

command

Result:

example

P.S.: Same for space. You don't have to use escape-query &nbsp;. Just use (simple space).

Upvotes: 3

ahmetd6234
ahmetd6234

Reputation: 1

you can use "br" ex: console.log("hello world
");

Upvotes: -1

natchkebiailia
natchkebiailia

Reputation: 631

use:

\xa0

space

\n

new line

your code will be:

function for_approve(){
   var approve = confirm(format_stock_id.length + "\xa0 Stock Record(s) is selected for approval.\n Do You Want to send it for Approval");
}

Upvotes: 0

Grim...
Grim...

Reputation: 16953

If you wanted to make the sentence a little neater with regard to plurals, you could do this:

if (format_stock_id.length == 1) {
    var approve = confirm("1 Stock Record is selected for approval.\n 
    Do You Want to send it for Approval");
} else {
    var approve = confirm(format_stock_id.length + " Stock Records are selected for approval.\n
    Do You Want to send them for Approval");
}

Little things like that make a good amount of difference in the final product.

Upvotes: 1

Stefanos Chrs
Stefanos Chrs

Reputation: 2518

You can use the JS Escape Characters in a string (ref: http://www.w3schools.com/js/default.asp) :

\'  single quote
\"  double quote
\\  backslash
\n  new line
\r  carriage return
\t  tab
\b  backspace
\f  form feed

Upvotes: 0

user3497034
user3497034

Reputation:

To jump to next line you need to use \n and for space no need to to write &nbsp, simply write whitespace character,


function for_approve(){
var approve = confirm(format_stock_id.length + " Stock Record(s) is selected for approval.\n Do You Want to send it for Approval");
}

Upvotes: 0

Related Questions