I need to disable couple of HTML Buttons on the page based on a boolean variable coming from the server.
I can access the variable on the JSP page. Do I need an event listener for this task? Any similar example would help a lot.
I'm not sure of the exact syntax but you could do something like this..
<input type="button" <%= disableFlag ? "disabled=\"disabled" : "" %> />
You don't need JS, just add the disabled property to your button.
<button type="button" disabled="disabled">Click Me!</button>
Related
The following code does not redirect to the given webpage
<form>
<button onclick='window.location.replace("../magnet/index.php")'>Replace document</button>
</form>
It is so because when you create a button within the form tags, it is created as a submit button by default. So, instead of redirecting the webpage, it submits the data and reloads the current webpage.
The following code will do the required job because now, the type of the button is button and not submit.
<button type="button" onclick='window.location.replace("../magnet/index.php")'>Replace document</button>
Even better, you can place your redirect code into a JavaScript function. Then you can call that function from within your HTML code. Like this
<script type="text/javascript">
<!--
function redirectTo(sUrl) {
window.location = sUrl
}
//-->
</script>
<button onclick="redirectTo('../magnet/index.php')">Get HTML!</button>
Hope this will work for you. Cheers
The answer was to add type="button" like #shivamag00 explained.
But be careful with replace(), it's not possible to use "back" to navigate back to the original document since you are replacing the history state.
An alternative is to use the assign() function, (documentation here)
Suppose you have a base url as
www.website.come
and want to go to
www.website.come/new-page
it's simple
<button type="button" onclick='window.location.assign("new-page")'>Go to new page</button>
It's worked for me, hope it's useful for someone else.
I need to use an asp.mvc form post. I use some angularjs on the client side. I know this question is not doing everything the "angular way".
What I need to do is set a variable $scope.IsUploadingData when the post happens so I can disable the buttons and show something to indicate progress. I have tried using ng-click, but it seems to stop the post from happening. Is there anyway to set the variable without interrupting the form post?
#using (Html.BeginFormAntiForgeryPost(Url.Action("Accept", "Members", new { area = "Testing" })))
{
other form stuff here
<span class="input-group-btn">
<button ng-disabled="IsUploadingData == true" name="accept" type="submit">Submit</button>
<button class="btn btn-default" ng-disabled="IsUploadingData == true" name="reject" type="submit">Reject</button>
<img ng-show="IsUploadingData" src="/SiteMedia/spinner[1].gif" />
</span>
}
It looks like you could use ng-submit to control the submission process and set $scope.IsUploadingData in the function you call from ng-submit. This is a decent write-up on ng-submit: http://learnwebtutorials.com/angularjs-tutorial-submitting-form-ng-submit
i need to open two links when a button is clicked in the html page. I figured it as by calling onclick function and creating anchor tag using createElement in Javascript. But how to include another link?? Is there a way to give a href in button tag??
You can simply do that with javascript
window.open(url1);
window.open(url2);
And if you want to open one of that links in curren window you can replace window.open by this
window.location = url1;
<input type="button" value="Double Clicker" onclick="window.open("http://www.google.com/"); window.open("http://www.youtube.com/");" />
see this link for further information,
You need to use a javascript event to make the page go somewhere
<input type="button" name="button1" value="Go To Url" onClick="window.navigate('URL')">
You can also use
location.href=" ";`
Try to see what the location object can do => http://www.w3schools.com/jsref/obj_location.asp
You should be able to load two tab.
why dont u use bootstrap
<a href="#" class="btn btn-default">
It displays a button with link going to what is mentioned in href
What I'm doing now is this:
<div style="display:none;">
<asp:Button runat='server' OnClick='OnDoClick' ID="b1" />
<asp:HiddenField runat='server' ID="SecretValue" />
</div>
function doPostb(value)
{
$('#SecretValue').val(value);
$('#<%=b1.ClientID%>').click();
}
so basically I need to post to a page method and send some value to it
anybody knows a more straightforward way of doing this ?
Straightforward? Wrap your div in a form tag and do:
$("#your_new_form").submit()
If you want to do it without the page re-loading, you could try jQuery's post function.
If you want to do it without the page re-loading, you could try jQuery's submit function, which would behave the same as the click of a submit button, but might be more semantically appropriate.
You might also want to look at asp.net's doPostBack function.
You can use __doPostBack method of asp.net Client-library.
function doPostb(value)
{
$('#SecretValue').val(value);
__doPostBack('<%=b1.UniqueD%>','');
}
I can't get that why you mentioned about PageMethods ??
I have a textbox on my page that ppl can input numbers, by clicking the button "submit" I want it to be the same as clicking the id in the list, which would redirect to the show page. How can I do that?
<g:link action="show" id="<g:javascript>document.getElementById('TextBox').value()</g:javascript>">
<input type="button" class="bigbuttonstyle" value="Submit" name="Submit" /></div>
</g:link>
Above won't work... but that's something i want... please advise. Thanks!!
That won't work because when the link tag renders HTML, it uses the ID attribute to build the URL. I would just use some behavioral JavaScript to bind a click event to your button that would issue a redirect for you. So using something like jQuery it would look a little like this...
<button id='show-btn'>Show</button>
$(function() {
$('#show-btn').click(function() {
window.location = '/path/to/show/' + $('#TextBox').val();
});
});
What's nice about this also is that you get to remove inline JavaScript out of your markup which is becoming an anti-pattern.