0

idI have a form from which I trigger the Bootbox dialog popup window like this:

$(function() {
  return $("#buy_order_btn").click(function() {
    return bootbox.dialog({
      title: "Confirm Buy Order",
      message: " // here should come the product name from the initial form"
    });
  });
});

Question: How can I display the values from the initial order form within the message part in bootbox?

I was thinking about something like

var product = $("input[id='product']").val()

but i am not sure. Please advise

Edit:

the initial form looks like this:

<form>
<input type=text id=product>
</form>
domi771
  • 450
  • 1
  • 9
  • 21
  • Are you trying to work with the content of `message` ? In that case, you need to add the whole form into the message. Otherwise, show the whole html ! Where is the input you are trying to work with ? – Nico Sep 15 '14 at 14:22
  • @Nico - the data I want to display within bootbox.dialog is in the initial form. – domi771 Sep 15 '14 at 14:35
  • Don't forget to add `"` between the attribute value : `type="text"` and `id="product"`. – Nico Sep 15 '14 at 15:09

1 Answers1

0

If your form is like

<form>
  <input name="product" value="productValue"/>
</form>

You can access the value of input the way you want i.e. $('input[name="product"]');. You absolutely need the attribute name to exist on the input otherwise it won't work. Be careful not to mix ' and " in your selector.

If your input have an id or a class

<input id="idOfInput" class="classNameOfInput" name="product" value="productValue"/>

You can access it with:

$('.classNameOfInput').val();
$('#idOfInput').val();

It is much faster to select by classname or by id than by attribute so I advice you to use class or id. See this answer for more information about performance.

As you edited the question here is how to acheive what you want :

$(function() {
  return $("#buy_order_btn").click(function() {
    return bootbox.dialog({
      title: "Confirm Buy Order",
      message: $('#product').val() // The product code here.
    });
  });
});
Community
  • 1
  • 1
Nico
  • 6,395
  • 4
  • 25
  • 34