How do you put a string variable in the confirm() function in JavascriptHTML? - Stack Overflow

I am trying to confirm with the user if the following string he or she is about to enter is correct but

I am trying to confirm with the user if the following string he or she is about to enter is correct but the confirmation box won't appear. Here is that segment of the code:

<html xmlns="" xmlns="">
<head>
<script>
   function validateForm(){
      var pkey = document.forms["createProductForm"]["pagekeyTF"].value;
      var agree = confirm("Is this your product?\n\n ${pkey}");

      if(agree) //Do something
      else //Do something else
   }
</script>
</head>
<body>
   <form name="createProductForm" controller="actions" action="ImplementNewProduct" onsubmit="return validateForm()" method="post">

      <g:textField id="productTF" name="productTF" value="My Product" />       
      <button id="createProductID" name="createButton" value="Create Product">Create Product</button>

   </form>
</body>
</html>

Am I not allowed to pass in string variables in the confirmation function? Because if I take off the ${pkey} it works fine but it does not include the user's input and that is not what I am not trying to achieve. Any help? Thanks!

I am trying to confirm with the user if the following string he or she is about to enter is correct but the confirmation box won't appear. Here is that segment of the code:

<html xmlns="http://www.w3/1999/html" xmlns="http://www.w3/1999/html">
<head>
<script>
   function validateForm(){
      var pkey = document.forms["createProductForm"]["pagekeyTF"].value;
      var agree = confirm("Is this your product?\n\n ${pkey}");

      if(agree) //Do something
      else //Do something else
   }
</script>
</head>
<body>
   <form name="createProductForm" controller="actions" action="ImplementNewProduct" onsubmit="return validateForm()" method="post">

      <g:textField id="productTF" name="productTF" value="My Product" />       
      <button id="createProductID" name="createButton" value="Create Product">Create Product</button>

   </form>
</body>
</html>

Am I not allowed to pass in string variables in the confirmation function? Because if I take off the ${pkey} it works fine but it does not include the user's input and that is not what I am not trying to achieve. Any help? Thanks!

Share Improve this question edited Aug 2, 2013 at 6:03 tim_yates 171k29 gold badges358 silver badges353 bronze badges asked Aug 1, 2013 at 23:19 Eli DavilaEli Davila 5772 gold badges6 silver badges14 bronze badges 4
  • clearly I could of also put var agree = confirm("Is this your product?\n\n" + pkey); If you guys aren't familiar with gstrings from groovy. – Eli Davila Commented Aug 1, 2013 at 23:26
  • Oh and I put value="My Product" inside the textfield for testing purposes so that way I can always get a value back. – Eli Davila Commented Aug 1, 2013 at 23:28
  • 1 You need to check the error console of the browser (Ctrl+Shift+J) to see if any js error occurred. Also check the rendered html (right click, view sourcE). – mshsayem Commented Aug 2, 2013 at 0:36
  • 2 Why don't people google before they ask ? – zzlalani Commented Aug 2, 2013 at 6:06
Add a ment  | 

1 Answer 1

Reset to default 2

Edit it like this :

var pkey = document.forms["createPixelForm"]["pagekeyTF"].value;
var agree = confirm("Is this your product?\n\n " + pkey);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745279201a4620197.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信