Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello all,
I am currently working on some Javascript to make a shopping cart so you will soon be able to order food online from this sub sandwich restaurant online. I have many of the main features working that I have been wanting to accomplish.
First I was doing validation of the controls on a button click so it will do them all at once.Now I switched it so as you select 1 option the value is inserted into a JSON object and I am doing the validations as the object is being built. This took quiet a bit of work but I believe I have this almost finished now to.
Although one problem that I have come along when working with this is a simple problem I think that should be easy to solve for many of you.
Before I was using multiple Div’s to hold different error messages and I had a breakline in-between the div’s so all the messages were not on one line.Now I am trying to do all of this in one single div element. I have this working with the multiple messages but the error is everything is on one single line. I would like each error message to be on a new line so it looks a lot cleaner.

Can someone help me solve this problem? Here is what I currently have :-

JavaScript
//this is my current code how I have it working with a single div
//HTML
<!--Add item button -->
		<h4>8). Add Item</h4>
		<button id="addToOrder" type="button">Add to order</button>
        <div id="order-message" class="validation alert"></div>
//JavaScript
        $('.validation').html('');
	    if (! lunchBag.bread) {
            var breadMessage = "You need to select a bread.";
            $('#order-message').html(breadMessage);
            $breadValid.html(breadMessage);
	        isValid = false;
	    }

//old version
		    document.getElementById("breadValid").innerHTML = breadValid;
		    document.getElementById("breadValid btn").innerHTML = breadValidbtn;
		    document.getElementById("fillingValid").innerHTML = fillingMessage;
		    document.getElementById("fillingValidbtn").innerHTML = fillingMessage;
Posted
Updated 26-Nov-14 19:41pm
v2
Comments
SRS(The Coder) 27-Nov-14 1:44am    
I think putting '<br />' after each of the message in div content will definitely solve your problem here.

1 solution

this solved my question

JavaScript
$('#order-message').html(breadMessage + '<br>');
</br>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900