This is my HTML so far
<button type="button" formaction="contact.html">Get In Touch!</button>
For some reason when I click on the button in a browser it doesn't take me to the contact.html page. All the pages that came up in google helped me learn new button attributes, but I couldn't figure out how to make the page redirect on click.
If you are using bootstrap, you can use this to do it for you:
Link Button
See http://www.w3schools.com/bootstrap/bootstrap_buttons.asp
Try the following:
<input type="button" onclick="location.href='contact.htm';" value="Contact" />
The better way is that you surround the above code with <form></form>.
Try these methods:
<!-- Using window.location.href = 'URL' -->
<button onclick='window.location.href = "https://stackoverflow.com"'>
Click Me
</button>
<!-- Using window.location.replace('URL') -->
<button onclick='window.location.replace("https://stackoverflow.com")'>
Click Me
</button>
<!-- Using window.location = 'URL' -->
<button onclick='window.location = "https://stackoverflow.com"'>
Click Me
</button>
<!-- Using window.open('URL') -->
<button onclick='window.open("https://stackoverflow.com","_self","","")'>
Click Me
</button>
<!-- Using window.location.assign('URL') -->
<button onclick='window.location.assign("http://www.stackoverflow.com")'>
Click Me
</button>
<!-- Using HTML form -->
<form action='https://stackoverflow.com' method='get'>
<input type='submit' value='Click Me'/>
</form>
<!-- Using html anchor tag -->
<a href='https://stackoverflow.com'>
<button>Click Me</button>
</a>
How about this?
<button type="button">Get In Touch!</button>
Related
How can I input a link in the button when I press the button?
<div class="buttons">
<span class="sold-out-tag position-top-right">Best Seller</span>
<button class="btn custom-btn position-bottom-right"> Add to cart</button>
</div>
Also you can trigger a link by JavaScript.
<button
onclick="window.location(this.getAttribute('data-link'))"
data-link="/hello">go to hello</button>
One way could be to use an anchor tag instead of the button and make it look like a button.
HTML:
<div class="buttons">
<a class="btn custom-btn position-bottom-right"> Add to cart</a>
</div>
CSS:
.custom-btn {
border: medium dashed green;
}
Alternatively, you could do:
<button class="btn custom-btn position-bottom-right" onclick="location.href='yourlink.com';"> Add to Cart </button>
Try this:
<a href='http://my-link.com'>
<button class="GFG">
Click Here
</button>
</a>
You can use the anchor tag and provide a Bootstrap class for the button, like,
<a class="btn btn-success" href="link"> Add to Cart</a>
If the label "Add to cart" matches the expectations, we'd be talking about a form. A form that causes an element to be added typically uses the POST method:
<form class="buttons" method="post" action="/path/to/add/to/cart/script">
<input type="hidden" name="product" value="123">
<span class="sold-out-tag position-top-right">Best Seller</span>
<button class="btn custom-btn position-bottom-right"> Add to cart</button>
</form>
Alternatively, there's GET as well:
<form class="buttons" method="get" action="/path/to/add/to/cart/script?product=123">
<span class="sold-out-tag position-top-right">Best Seller</span>
<button class="btn custom-btn position-bottom-right"> Add to cart</button>
</form>
Since GET doesn't carry additional payload, you'll get the same effect with a regular anchor:
Add to cart
You don't want search engine spiders to populate carts, so you typically leave GET for data fetching.
I tried using solution on the web but can't get working I want to display tooltip of a disabled button. I use materialized css.
Here is my html of button:-
<div class="input-field col s7">
<button id="btn" class="btn blue-grey tooltipped" data-tooltip="Button will be Enabled after file upload" disabled>Submit</button>
</div>
Actually you can't enable the tooltip for the disabled <button> or <a>, but you can do a trick and wrap your button inside a <span> then add the tooltip to that <span> element instead of <button> itself. So you have to manage the <span> tooltip in enabling/disable events.
So your code should be something like this:
document.addEventListener("DOMContentLoaded", function() {
var elems = document.querySelectorAll(".tooltipped");
var instances = M.Tooltip.init(elems);
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<div class="input-field col s7">
<span class="tooltipped" data-tooltip="Button will be Enabled after file upload">
<button id="btn" class="btn blue-grey" disabled>Submit</button>
</span>
</div>
I am using the PrimeNG dialog component and I have a modal dialog from which, on the click of a button, I want to show another modal dialog.
What is happening is that my second modal dialog is not really modal, because I only see the content of the dialog following the button.
I do change [appendTo] attribute of the p-dialog for the second modal dialog but it does not seem to work properly.
How can I open nested dialog in a p-dialog?
Dialog in a angular 2 component:
<p-dialog header="Create/Edit Financial Flow" [visible]="display$ | async" modal="modal" width="500" height="600" responsive="true" [resizable]="false" [closable]="false">
<financial-flowdialog #myfinancialflowdialog (onCloseDialog) ="closeDialog()" [flowdata]="selectedFlows$ | async"></financial-flowdialog>
</p-dialog>
When clicking a button within the first modal dialog, should open a second dialog. Below the definition of the nested dialog:
<p-dialog header="Title" [(visible)]="display" [appendTo]="body" *ngIf="display" modal="modal" width="500" height="600" responsive="true"
[resizable]="false" [closable]="false">
<div class="container-fluid">
<form (ngSubmit)="onSubmit()">
<div class="pull-right top-buffer ">
<button type="button" class="btn btn-primary" (click)="closeDialog()">Cancel</button>
<button type="submit" class="btn btn-primary">Select</button>
</div>
</form>
</div>
</p-dialog>
<button type="button" #mybtn [value]="value" ngDefaultControl [formControlName]="key" [id]="key" [ngStyle]="style" (click)="openDialog()">{{label}}</button>
I can open the first dialog but when I click on the button to open the second dialog, the content of dialog shows up like a normal div. Below the html rendered:
<section>
<div id="nestediag" ng-reflect-form="[object Object]" class="ng-pristine ng-invalid ng-touched">
<!--template bindings={
"ng-reflect-ng-if": "true"
}--><p-dialog header="Title" height="600" modal="modal" responsive="true" width="500" ng-reflect-visible="true">
<div class="container-fluid">
<form class="ng-untouched ng-pristine ng-valid">
<div class="pull-right top-buffer ">
<button class="btn btn-primary" type="button">Cancel</button>
<button class="btn btn-primary" type="submit">Select</button>
</div>
</form>
</div>
</p-dialog>
<button ngdefaultcontrol="" type="button" value="Select a payee" ng-reflect-name="flowpayee" ng-reflect-ng-style="[object Object]" ng-reflect-value="Select a payee" ng-reflect-id="flowpayee" id="flowpayee" class="ng-pristine ng-valid ng-touched" style="width: 100%;">Select a payee</button>
</div>
</section>
You can solve this problem by appending the second dialog to the document body by using the appendTo attribute, e.g.
<p-dialog appendTo="body">
...
</p-dialog>
Defining a componentref variable and using [appendTo]="Componentref" solve the issue.
See discussion https://github.com/primefaces/primeng/issues/656
You can solve this problem by appending the second dialog to the document body by using the appendTo attribute, for e.g.
<p-dialog appendTo="body">
.............
</p-dialog>
He wants you press the button "Download" disappearing text.
<button class="btn btn-default" type="button" id="getInfo" onclick="getVideosInfo();">Download!</button>
<div id="infobox">
My TEXT
</div>
Here is what you can do, this code uses just 3 extra lines of jQuery code. Following is my solution:
$('#getInfo').click(function(){
$('#infobox').hide();
});
function getVideosInfo(){
//...
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn btn-default" type="button" id="getInfo" onclick="getVideosInfo();">Download!</button>
<div id="infobox">
My TEXT
</div>
Here is an external fiddle supporting this.
you need of course java script... but then it works like the following
function getVideosInfo(){
infobox = document.getElementById("infobox");
infobox.style.display = "none";
}
<button class="btn btn-default" type="button" id="getInfo" onclick="getVideosInfo();">Download!</button>
<div id="infobox">
My TEXT
</div>
I have two buttons:
<button onclick=initialize() id="1" data-role="button" data-mini="true" data-corners="false" data-theme="b">Show My Position</button>
<button onclick=calcRoute() id="2" data-role="button" data-mini="true" data-corners="false" data-theme="b">Evacuate !</button>
I want to have the second button disabled by default, and have it enabled if clicking on the first button. How do I accomplish this?
Please see the following answers to questions:
Disable Buttons in jQuery Mobile
How to disable html button using JavaScript?
The simplest approach would be (just a pure example w/out taking into consideration browsers, etc):
<html>
<head>
<script>
function enableButton2() {
document.getElementById("button2").disabled = false;
}
</script>
</head>
<body>
<input type="button" id="button1" value="button 1" onclick="enableButton2()" />
<input type="button" id="button2" value="button 2" disabled />
</body>
</html>