Greetings,
I've been scanning the internet on how to do this, but so far no luck. There are numerous solutions posted, especially on this website (thank you for that), but none seem to work for me. This will most probably be because I am only learning asp.net since 4 months now, and lack the necessary knowledge.
What I would like to do is set focus on the username input textbox when the page is loaded. I've seen many solutions, such as "defaultfocus", body onload, etc, etc. Anyone can give me a simple way to accomplish this?
Our project is a MVC 2 Web application. We have a master site, which collects all the contentplaceholders. Here is the link to the logon.aspx
<div id="Clogin" onclick="logout();">
<asp:ContentPlaceHolder ID="LoginContent" runat="server" />
</div>
The LogOn.aspx is practically the same as the auto-generated one. And here is the textbox I would like to set focus on:
<div class="login-field">
<%: Html.TextBoxFor(m => m.UserName)%>
<%: Html.ValidationMessageFor(m => m.UserName) %>
</div>
How can I trigger the onload event, be it in the master page, or the LogOn page, so that the focus is generated on that particular textbox?
Thanks in advance, and apologies for having to rely on your knowledge.
Sincerely,
Nicolas
You will need to use javascript for this. If you are using jquery you could include the following script:
$(function() {
$('#UserName').focus();
});
Another possibility is to do this in the body tag:
<body onload="document.getElementById('UserName').focus();">
Related
So I've spent a day on Google, and trying bits of jquery/javascript to do what I'm looking to do and am officially stuck.
I'm building a site using Squarespace, with the Marquee theme applied. I would like to be able to add a custom link in the primary navigation to send users to an alternative language version of each specific page.
But, I'm struggling. Ive found solutions on here that should work, but I don't think I'm applying it right. Ive tried adding a single link to the navigation and using a script on each page (in the code injection point of the head section) point that link somewhere else.
This would mean I have a single link in the navigation (which is standard across the site) pointing users to whichever page I want...on a per page basis. I know there is a solution out there....just can't make it work!
The section I need the link to work from is:
<div id="desktopNav" data-content-field="navigation-mainNav" data-annotation-alignment="bottom left">
<nav class="main-nav" id="yui_3_17_2_1_1450478013910_660">
<div class="nav-wrapper" id="yui_3_17_2_1_1450478013910_659">
<ul class="cf" id="yui_3_17_2_1_1450478013910_658">
<li class="page-collection">
<span>Menu</span>
</li>
</ul>
</div>
</nav>
</div>
None of this can be edited directly though...
I was thinking something like this could work, but I cant work out how to apply it to my situation...
Change href value for a hyperlink
Any help, gratefully received!
I fixed it...using this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a[href*="original.site"]').attr('href', 'http://website.com');
});
</script>
It allows me to point a single link in the navigation (which cant be edited directly) to whatever I want it to go to.
I'm working on a website redesign based on the Bootstrap 3 framework.
In configuring the site's contact form, and implementing a captcha, I've run into an issue with my CSS.
Everything works well in Chrome, but in Firefox, the captcha overflows the form boundaries, and is off to the side, whereas in Chrome, it's under the form and integrated more normally. To attempt to fix this, I put the captcha (which was outside of the form's div tags originally) inside it's own div group. That fixed part of the issue, in properly aligning the captcha under the rest of the form.
However, now that I've done that, the captcha (and the form label it's associated with) overruns the form boundaries on both sides, and doesn't display properly in either Chrome or Firefox. Further, it doesn't space properly, despite being in its own div.
http://www.weatherworks.com/contact/contact.php
I'm not sure how - or if - I can fix this. I'm a student and web design is more of a hobby for me; I'm actually doing this redesign as part of a weather-related internship. I'm fairly knowledgeable on HTML and CSS, but am pretty lost with this issue. Was hoping someone here who's worked with forms and/or Bootstrap might have some insight for me.
Thanks!
You missed a closing tag of the <div class="form-group" id="commentTxt">. Place a close tag above the next <div class="form-group">
<div class="form-group" id="commentTxt">
.
.
.
</div> <!-- Add this div -->
<div class="form-group">
<label class="col-lg-2 control-label">Verify Humanity</label>
I have this
<form id="form_837299" class="appnitro" method="post" action="insert.php"> <paper-input label="Title" name="title" maxlength="255">
</paper-input>
<paper-input floatinglabel multiline label="text" name="text"></paper-input>
<li class="buttons">
<input type="hidden" name="form_id" value="837299" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
I have problem with POST data - nothing is sended in "text" and "title" (all in paper-input).
I modified the template and attribute "name" now is in one div, which Polymer created. But no data are sent.
print_r($_POST); shows me only this:
Array ( [form_id] => 837299 [submit] => Submit )
Anybody knows how use Polymer and Material UI on form?
Only elements that extend native form elements automatically get submitted with forms. paper-input extends core-input which has an input inside it as opposed to extending it. See this mailing list discussion for additional discussion and this StackOverflow post for possible solutions.
Something like this jsbin maybe?
Update: Here's the same thing in web component form.
Update: Looks like the creator of ajax-form has added this functionality.
Update: Also consider using iron-form.
According to the Polymer docs the way to do this is to just create a regular form input and wrap it in the <paper-input-decorator>
https://www.polymer-project.org/docs/elements/paper-elements.html#paper-input
I've tried it out and it works fine. Some better form support would be cool, but oh well. This stuff still kind of rocks.
UPDATE: I've built a bower package (polymer-rails-forms) to deal with forms in polymer, tailored specifically to the ActiveRecord input naming scheme but it will work with any old form really. It's still relatively new, but it covers most input types, basic validations, xhr and non-xhr submits and has a couple cool extras like image, json, and location* fields.
the location fields depend on the Google Map Places API
Thanks to a previous question I found a useful link on multiple buttons.
http://weblogs.asp.net/dfindley/archive/2009/05/31/asp-net-mvc-multiple-buttons-in-the-same-form.aspx
What I want to do is have a cancel button on my page, similar to this;
<button name="button" type="button" onclick="document.location.href=$('#cancelUrl').attr('href')">Cancel</button>
<a id="cancelUrl" href="<%: Url.Action("Index", "Home") %>" style="display:none;"></a>
However although this code works, I really want to go back to the previous page. For Web Forms I could use the javascript Back() or Go(-1) functions, but they relied on postbacks.
I could of course hard code the previous page and controller as I have done above. However I am struggling to find links that explain to me how Url.Action works. Because if I do this, I also need to include an index parameter, and I am not clear how the syntax works for that.
It seems odd the amount of coding to do this.
Out of curiosity, I am also wondering how you TDD client side code like this.
<input type='button' onclick='javascript:history.go(-1);return false;' />
the javascript go function does not do any postback.
also, if you are using MVC2 i would not use the server controls like 'Button' you risk ending up with unexpected results.
Does anybody know of a simple jQuery form processing tutorial that actually works?
I have a form I want to process via jQuery/Ajax nothing difficult in PHP but in jQuery and AJAX can I get it to work - no, all the tutorials are based round sending e-mails (or just lists of more lists of more lists of tutorials - hate those)
All I want to do is learn how to send a form via jQuery and AJAX to another page, save the data in a DB without having to leave the first page. I have tried all sorts but nothing works properly. Here is my form:
<form id="form">
<input type="text" name="abc" />
<input type="text" name="def"/>
<input type="text" name="ghi"/>
<input type="submit" name="try" id="try" />
</form>
Now what do I actually do? Sounds silly I know (and I guess I'll get another -1 star for this question) but I will be honest a GOOD simple tutorial would be really useful not just to me but to the others. I know php but jQuery/Ajax - just don't know/understand. I will not be alone
This is one of the good tutorials on how to submit forms using ajax and php.
This link is a reference teaching how to submit forms via jQuery/AJAX. Have the form post to a PHP page to handle the form data.
In short, your jQuery code would look similar to this:
$("#form").submit( function()
{
// Handle validation or any extra data here.
// Return true if validation passed and the data should be posted
// Return false if the form should not be submitted
// You can also do any extra work here that you like before returning,
// including changing something on the page or showing the user a message.
}
There's a cracking plugin for this:
http://plugins.jquery.com/project/form/
It's as easy as:
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});