1

I have an Input Field. When I click on this field it will add product into the Cart and moves on the Cart Page.

<input type="button" class="bgbutton"
value="Add to Shopping Cart" id="addtocart" name="addtocart"
onkeypress="window.event.cancelBubble=true;"
onclick="if (document.forms['form590'].onsubmit()) { document.forms['form590'].submit(); } return false;"
target="_blank">

I have given the tag target but unfortunately it does not work. Kindly give me any Solution in JQuery / JavaScript etc.

SOLUTION

Simply I add target attribute in form tag. that's it.

$("form").attr("target", "_blank");

I resolved my issue.

Thanks

John Brad
  • 447
  • 1
  • 10
  • 26

2 Answers2

4

Simply you can use anchor tag instead of the button

<a
     href="CART_URL" <-- here goes cart url you want to open in the new tab
     class="bgbutton"
     id="addtocart"
     name="addtocart"
     onkeypress="window.event.cancelBubble=true;"
     onclick="document.forms['form590'].onsubmit() ? document.forms['form590'].submit() :; return false;"
     target="_blank"
>Add to Shopping Cart</a>
Sunil Kashyap
  • 2,946
  • 2
  • 15
  • 31
1

To open a new tab you can use the following code.

<input type="button" class="bgbutton" value="Add to Shopping Cart" id="addtocart" name="addtocart" onkeypress="window.event.cancelBubble=true;" onclick="window.open('NewPage.aspx', 'NewPage');" >

To move between pages

<input type="button" class="bgbutton" value="Add to Shopping Cart" id="addtocart" name="addtocart" onkeypress="window.event.cancelBubble=true;" onclick="location.href = 'NewPage.aspx';" >

For more details you may want to refer to the following questions:

In JQuery you can use the following

<script>
        $(document).ready(function () {
            $(".bgbutton").click(function () {
                window.location.href = "NewPage.aspx";
            });
        });

</script>

You can carry the variables to the other page through the URL like below.

 <script>
        $(document).ready(function () {
            var name = "coder";

            $(".bgbutton").click(function () {
                window.location = 'NewPage.aspx?username=' + name;
            });
        });

 </script>

To get the passed values to open up in new tab use the following

 <script>
        $(document).ready(function () {
            var name = "coder";

            $(".bgbutton").click(function () {
                window.open('NewPage.aspx?username=' + name,"")
            });
        });

 </script>

In order to understand how to retrieve a value from a URL, you might want to refer to the following question: Get url parameter jquery Or How to Get Query String Values In js

Barrosy
  • 1,407
  • 2
  • 25
  • 56
Coder
  • 338
  • 2
  • 19
  • Can you show me how you are doing it? It would be great if you can share your script file – Coder Jul 01 '19 at 11:34
  • @JohnBrad What does not work for you? Coder is explaining things quite correctly. Just using `window.location` in JavaScript will solve the problem for you. You do not want to use the `target` HTML attribute. – Barrosy Jul 01 '19 at 11:47
  • My Onclick Code. onclick="if (document.forms['form590'].onsubmit()) { document.forms['form590'].submit(); } return false;" is not working in window.open. – John Brad Jul 01 '19 at 11:59
  • When I use $(".bgbutton").click. it is going on Cart Page. I want it will be open in new Tab. Second after using this, My Add to Functionality does not work. – John Brad Jul 01 '19 at 12:00
  • @JohnBrad why do you use that if condition? please show me the code of adding to your cart – Coder Jul 01 '19 at 12:20
  • Its a NetSuite Application. This application works like that. If condition is produced through NetSuite Tag. – John Brad Jul 01 '19 at 12:23