I feel like I'm missing something simple, so apologies in advance if the answer should be obvious, but here goes:
On my page, I have a number of lists, the intended behaviour is for the user to click on a list item, and have a details pane populated with data (some of which is universal, some of which pertains to a particular day) -- so far so good. However, the details pane also contains a form that allows the user to select a different day. All of this works swimmingly in IE10. However, in Firefox, the "Select day" form is completely unresponsive -- the input box doesn't allow input, nor does the submit button work. In fact, none of the text in the details pane is selectable, it's visible, but the user can't do anything with it.
On the main page, I have an empty div with the id "details" that's loaded thusly:
$("ul").on('click', 'li', function(event) {
if($("#details").is(":hidden")) $("#details").toggle("slow");
var id = this.id.substring(2);
$.ajax(appRoutes.controllers.Dashboard.getDetails(id)).done(
function(data) { $("#details").html(data); });
});
The details div is loaded with this html:
<h2>Details</h2>
<div id="universal details">
...data...
</div>
<div id="dailyInfo">
<script>
$(function() {
$("#daiDate").datepicker({dateFormat: "mm-dd-yy"});
});
$("document").ready(function(){
$("#detailsform").submit(function(event) {
event.preventDefault();
appRoutes.controllers.Dashboard.dailyDetails().ajax({
data : $("#detailsform").serialize(),
success: function(data) { $("#dailyInfo").html(data); }
});
});
});
</script>
<h4>Daily Details</h4>
<form action="/dfdetails" method="GET" id="detailsform" enctype="multipart/form-data">
<input type="hidden" name="partID" value="146" />
<input type="text" name="dataDate" id="daiDate" value="05-22-2014" />
<input type="submit" value="Get" class="btn primary" id="getDAI">
</form>
<div "daily details">
...data...
</div>
</div>
To reiterate, this all works perfectly in IE10, for reasons beyond my control (corporate policy), I can't test this in Chrome. I'm using jQuery 2.1, if that makes any difference.
Related
I am new here, so maybe you need to give me some hints about how everything works in this community. I was already reading a lot here on Stackoverflow but finally signed up.
I am designing a small website for a museum near me which is a non-profit organization. They have a huge collection of ammunition and the information is currently available on paper.
I want a website where I can enter a number and the appropiate information is shown. Everything works so far in my test site. (since no internet available there, it should run locally on a android tablet later)
The only problem I have is that the form submit works with the button, but not with the enter key or "open" key on the androids numberpad.
I am also quite new to javascript-coding since I come from electronics and c-programming on microprocessors, so I may have made mistake.
i currently have the iframe in the main page, but i originally wanted it to open up in a modal. It did not work properly, so maybe I may try that later again.
Live demo here: museum.smallfilms.ch/drei
The code for the form is the following:
<!-- Jumbotron Header -->
<header class="jumbotron hero-spacer">
<h1>Katalog:</h1>
<p>Mit der Munitionsnummer können hier weitere Informationen zur jeweiligen Patrone angezeigt werden.</p>
<p>
<form onsubmit="searchpage()">
<input type="number" pattern="\d*"/min="1" max="9999" id="num" >
<button type="button" class="btn btn-danger" onclick="searchpage()" id="search">Suchen</button>
</form>
The Javascript code is the following:
function searchpage() {
var num = document.getElementById('num');
var targetFrame = document.getElementById('targetFrame');
if (num.value) {
var page = 'pages/' + (+num.value) + '.html';
targetFrame.setAttribute('src', page);
}
}
If you need more code I can deliver this. Just let me know that you need.
The site is now designed to show something for the numbers 1 and 2.
The whole site uses bootstrap and the sites displayed in the iframe use strapdown.js for easier editing. (We need to digitalize about 900 datasets in the end)
I think it is only a small mistake somewhere but after hours of coding and searching the internet i still did not get the source of the error.
Thanks in advance for any help and hint.
Dabbax
Edit: if it helps, i packed the whole page into a zip... museum.smallfilms.ch/drei/drei.zip
I think that the error comes from the line where you are calling the function searchPage(). I would recommend you to try the line below :
<input type="sumbit" class="btn btn-danger" onclick="searchpage()" id="search" value="Suchen">
In this case, when you press enter, the form will be submitted and call the searchPage function.
On your code for the form, try:
<button type="submit" class="btn btn-danger" onclick="searchpage()" id="search"> Suchen </button>
edit: Shaam's answer can be correct but if you say input then you just trying to make it a look like button with bootstrap, a more proper approach would be input type="button" but in your case you should say that this is a button that submit the form.
That's why you should use button and not input here.
This could be your html:
<form id="searchForm" action="some_url">
<input type="number" pattern="\d*"/min="1" max="9999" id="num" >
<input type="button" value="Suchen" class="btn btn-danger entr" onclick="searchpage()" id="search">
</form>
Now add an event listener to the class entr and submit the form if the key is Enter. So the event listener in jquery like
$('.entr').keypress(function(event) {
if (event.which == 13) { // this is the enter key code
document.getElementById('searchForm').submit();
}
});
I've made a web application That starts from a specific amount and every time a donation is made it counts down and shows how much is needed. And at one time I might have about 10-20 of these counting down and I am always creating new ones. Now when I am doing that it would be nice that when I click the button it automatically focuses on the text field for ease of use. however I can't quite get that to work.
The window to set the countdown is shown using angularjs dialogs/modals. This means that when I click the a button it writes code onto the page that shows the dialog/modal and when I submit it it is removed from the page completely.
The first time around when I click the button it focuses on the text box and I can type the number and press enter and it's submitted, now I want to create a new one. I click the button, up comes the modal but now I have to grab the mouse, move it to the input and click it. Waste of time and not user friendly.
What I'm asking is for a way to have it focus on the text field when using modals every time I click the button.
here's the window:
<form name="formCountdown" novalidate class="css-form">
<div modal="showCountdownModal" close="showCountdownModal = false" options="opts" ng-cloak>
<div class="modal-header">
<h4>Enter Countdown Amount</h4>
</div>
<div class="modal-body">
<input id="focusbox" type="number" min="1" autofocus required ng-model="countDownAmount" name="countDownAmount" ui-keypress="{13:'setCountdown()'}" select-on-focus />
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary cancel" ng-disabled="formCountdown.$invalid" ng-click="setCountdown()">Set</button>
</div>
</div>
</form>
I've tried using autofocus, and that works fine the first time you press the button after loading the page. but the second and up it does not.
I've also tried using this jquery code with no luck:
<script>
$("#focusbtn").click(function() {
$("#focusbox").focus();
});
</script>
And now I am completely lost and would really love it if someone could help me out here.
Edit: forgot to put in the timeout, to make sure the browser is ready!
add the following line to your setCountDown() function:
$timeout(function (){
document.querySelector('#focusbox').focus();
},0)
You need to inject the $timeout in your controller
That will probably do the trick!
However, this will work, but dom manipulation should be done in a directive!
I copied your posted code together with the script and it works just fine. I'm not sure if I understood the problem but the autofocus works well in my end. Autofocus is present after the page has loaded or refreshed and even after the button has been clicked. Of course the autofocus will be removed if a click outside the input text has been triggered.
Morever, I think Autofocus is an attribute by HTML5. You might want to include in your HTML or maybe it is just a browser compatibility issue.
You can test or check if autofocus is supported by your browser at http://html5test.com/.
Hope this help somehow.
EDIT:
Try this on your script.
$(document).ready(function() {
$(".modalName").on('shown', function() {
$(this).find("[autofocus]:first").focus();
});
});
I have a program that acts sort of like a wizard, so it goes from Page 1, click next, page 2, click next, page 3, etc...on button clicks I am using javascript to put certain checkbox control values into localstorage. My problem is, when I press back to go to a previous page the control values are reset to 0/false. How can I make a pageload type effect in MVC to refill these values from local storage.
One option would be to use DIVs that are hidden:
#using(Html.BeginForm()) {
<div id="step1">
<!--form objects-->
<input type="button" id="to_step2_button" />
</div>
<div id="step2" style="display: none;">
<!--form objects-->
<input type="button" id="to_step1_button" value="Back" />
<input type="button" id="to_step3_button" value="Next" />
</div>
<div id="step3" style="display: none;">
<!--form objects-->
<input type="button" id="to_step2_button" value="Back" />
<input type="submit" id="finish_button" value="Finish" />
</div>
}
And use jquery/javascript hide/show the DIVs depending on the step.
This method has other benefits such as: you can use 1 page, 1 model, 1 form, no reloading needed.
Anecdote: I worked on a property rental website, and the listing form had 87 fields that were grouped, and each group had a tab in a tabbed view (which were just hiding and showing divs within the form). And we added Next and Previous buttons which cycled through the tabs. It worked really well, made sense to the client, and we didn't have to mess around with trying to maintain form field states between pages. Everybody won.
I decided to put JavaScript directly on my View that references my JavaScript file. I put what I called LoadPage() method in the #Javascript section at the top of my page...Inside the LoadPage() I had code that looked like this:
function loadPage(currentPage) {
var currentPage = currentPage;
if (window.localStorage.getItem("chkProvider") == 'true') {
document.getElementById('chkProvider').checked = true;
}
if (window.localStorage.getItem("chkSubscriber") == 'true') {
document.getElementById('chkSubscriber').checked = true;
}
}
This runs when the page loads and sets the values that I need updated. This is an example of how one might update their View using JavaScript and local storage. I hope my solution helps someone!
I got this code here:
It works fine as far as disabling and replacing the Submit button goes, but it will not submit the form. My form uses the 'get' method and submits data to another page.
<script type="text/JavaScript">
$('.button').click(function() {
$('.button').remove();
$('.holder').append("DONT DOUBLE CLICK ANYTHING IN A BROWSER");
$('.form').submit();
});
</script>
I have tried most things, including changing .form to the id of my form, still no joy, any ideas would be helpful.
HTML code
<form action="liftingConfirm.asp" method="get" id="frmArchiveConfirm">
<input name="con_id" type="hidden" id="con_id" value="<%=request.querystring("con_id")%>" />
<input name="sub_id" type="hidden" id="sub_id" value="1" />
<input name="liftingDate" type="hidden" id="liftingDate" value="<%=Session("currentUSDate")%>" />
<div class="holder"><input name="btnConfirm" type="submit" class="button" id="btnConfirm" value="Start New Lifting Gear Examination" /></div>
You're using the wrong selector, the .form is looking for a <form> with a class of form. Furthermore you should be using the on() syntax:
$('form').on('click', '.button', function() {
$('.holder').append("DONT DOUBLE CLICK ANYTHING IN A BROWSER");
$('#frmArchiveConfirm').submit();
$('.button').remove();
});
For your jQuery code to work you should include the frmArchiveConfirm to your jQuery code as below.
Replace $('.form').submit(); with $('#frmArchiveConfirm').submit();
else if you only having one form in the page just use $('form').submit();
When you come across bug like this don't forget to make use of the firebug or the browser development tools. You can easily figure out the bug and what's wrong in your code.
Interesting bug here that seems to be limited to IE and Webkit.
I have a basic form setup:
<div id="output">Form output is displayed here</div>
<form id="myForm" action="#" method="post">
<input type="text" name="username" id="usernameInput" />
<input type="submit" value="Submit" />
</form>
Now if I just submit the form through a normal page refresh, the next time I go to type text into the input field, I will get the browser's default auto-suggest dropdown (this is the intended behavior). However, if I highjack the form submission behavior in order to do an AJAX submit:
$('#myForm').submit(function () {
$('#output').text($('usernameInput').val());
return false;
});
Now when I submit the form, the output div updates, but the previous values that I input into the form aren't stored and no suggestions will be made when you type.
Does anyone have any creative solutions to this problem? Maybe an (gulp) iframe?
IE and WebKit only remember values that were submitted normally, and since you are submitting it through AJAX, those engines do not remember the values. Instead of an iframe, I would use a jQuery plugin for the autocomplete, like this one. Of course, with that solution, you will need to maintain a listing of what a user has typed in the past, which shouldn't be too hard.
test with these modifications in controlling submit:
$('#myForm').submit(function (e) {
e.stopPropagation();
$('#output').html($("#usernameInput").val() + "<br />");
});