0

working off this question: Passing data to Bootstrap 3 Modal

In all these examples, the data-id is sent to a text box, with this line:

<input type="text" name="bookId" id="bookId" value="" />

How do I send the data (may be as a variable) so I can make it the heading of the modal instead of using an input type. I tried something like this, but it does not work:

<p type="text" name="bookId" id="bookId" value="" />

For example, in this fiddle: http://jsfiddle.net/4XJ54/

the data-id "ISBN" is populated in the text box. How do I get the data-id "ISBN" to show up as the heading instead?

Community
  • 1
  • 1
user2883071
  • 960
  • 1
  • 20
  • 50

1 Answers1

2

Use text() function. .val() is for inputs and <p> does not support value.

$("#bookId").text(myBookId); // for <p>
$("h4.modal-title").text(myBookId);// for Modal title

Updated fiddle

Shaunak D
  • 20,588
  • 10
  • 46
  • 79
  • If I need to use this value to query a database, I can store it to a value in jquery and use the same variable in php correct? – user2883071 Apr 25 '15 at 13:38
  • Yes you can store it in a variable. And pass to php by using ajax – Shaunak D Apr 25 '15 at 15:36
  • Is there a better way of getting it into a php variable? I find using ajax very confusing. I was reading about using the data-id attribute, can this be applied here? – user2883071 Apr 25 '15 at 16:19
  • data-id does not related to server side. It is just a html storage. You have to use form actions or ajax – Shaunak D Apr 25 '15 at 16:24
  • @user2883071 more people will respond to your other questions and help you if you start accepting some answers to your previous questions, like this one – Wesley Smith Apr 28 '15 at 11:05