John Davidson

javascript - display full string in bootstrap modal using jquery instead of first word

0 comments
Message:


I am using php to fetch a name from a db and using jquery when I click on a button I want to display that name as html inside a bootstrap modal box . The problem is the name has spaces and I can only display the first word . ex. "my name " displays "my" instead of "my name"


My code :


html element created with php that holds name and toggles the modal :


 <div class = 'card__footer'>
<h3> ".$partner["storeName"]." </h3>
<a data-toggle = 'modal' data-val = ".$partner["storeName"]." data-target='#partnerModal' >
<button type = 'button'>View Reviews </button>
</a>
</div>

jquery to insert name as html in modal on show :


 $('#partnerModal').on('show.bs.modal' , (e)=>{
if(e){
var partner = $(e.relatedTarget).data('val'); //gets only first word !
console.log(partner);
$("#partnerTitle").html(partner);
}


});


My Answer:
If you are only displaying the first word of the name in the modal, it may be because you are not properly handling the spaces in the string. You can use the `html()` method in jQuery to display the full string in the modal.

Here is an example code snippet that demonstrates how to display the full string in a bootstrap modal using jQuery:

html





Display Full String in Bootstrap Modal
















In this code snippet, when the button with the id `openModal` is clicked, the name "John Doe" is displayed in the modal body using the `html()` method in jQuery. You can replace the hardcoded name with the name fetched from the database in your PHP code.

Rate this post

4 of 5 based on 6748 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us