Autofill on textbox (in Chrome) results in being prefilled without pushing enter - html

I have a very strange issue, that results in quite a lot of problems for our visitors.
On a normal textfield, Chrome (and other browsers) suggests strings to prefill. When you hover them and move the mouse away, they are not selected and written in the textbox.
However, in my setup, I have a weird case. When I hover my options, and then move the mouse it, it selects an item in the box. This results in an awful lot of "please enter an email" messages, while the user sees an e-mail on their screen.
See problem in this video:
https://www.youtube.com/watch?v=Vh2nb0_IR3Q
My markup for this particular e-mail:
<input type="text" name="Email" placeholder="E-mail" id="newUserEmail" class="email_input newinputtxt">
Does anyone have a hint? Because i am really lost...
EDIT:
Full ASP.NET MVC markup:
<asp:Content ID="Content1" ContentPlaceHolderID="plhMain" runat="server">
<h2>Indtast e-mail adresse</h2>
<div class="checkout__section checkout__section--login checkout_auth">
<div class="single_login">
<div id="newUserBox">
<div id="provideUserEmailBox">
<div class="email_auth">
<div>
<input type="text" name="Email" placeholder="E-mail" id="newUserEmail" class="email_input newinputtxt" />
</div>
<span class="red auth-error-text" style="display: none;" id="invalidEmailText">Der skal indtastes en gyldig e-mail</span>
<ul class="red_checkmarks" style="margin-top: 5px;">
<li>Vi bruger e-mail adressen til at sende en bekræftelse pa din ordre</li>
<li>Hvis du vil, kan du logge ind eller oprette en konto på næste side.</li>
</ul>
</div>
</div>
<div id="createNewUserBtnBox">
<input id="newUserBtn" type="button" class="button button--primary" value="Fortsæt" />
<span class="red auth-error-text" id="createNewUserErrorText"></span>
</div>
</div>
</div>
<div id="socialLoginList">
<button class="pfacebook" type="button" name="provider" value="facebook" title="Log ind med din Facebook konto">
Facebook
</button>
<button class="pgoogle" type="button" name="provider" value="google" title="Log ind med din Google konto">
Google
</button>
</div>
</div>
<script type="text/javascript">
$(function () {
$("#newUserEmail").keypress(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
$("#newUserBtn").click();
}
});
var auth = CheckoutAuthorizationFlow({ LoginUserBox: "#loginWithUserBox", NewUserBox: "#newUserBox" });
auth.Init();
var facebookLogin = function () {
var loginUrl = '/login?returnurl=' + encodeURIComponent(document.location.href) + '&r=' + (new Date().toUTCString()) + '&provider=facebook';
//alert('facebook login');
document.location.href = loginUrl;
return;
};
var googleLogin = function () {
var loginUrl = '/login?returnurl=' + encodeURIComponent(document.location.href) + '&r=' + (new Date().toUTCString()) + '&provider=google';
document.location.href = loginUrl;
return;
};
$(".pfacebook").click(facebookLogin);
$(".pgoogle").click(googleLogin);
});
</script>
</asp:Content>

So my roommate, who has been working a bit with Wordpress a couple of years back, just came by my computer and said:
"Wrap it in a form tag!"
So I told him that was a horrible idea, and he said "try it".
And I did.
And it fucking worked.
So tl;dr -> wrap it in a form tag, and it works... I'll go cry.

Related

How to create a copy text link?

I created a code and I want the visitor to be able to copy the BTC address <small type="text" id="copy-to-clipboard">{{ group.field_groupe_donation.value }}</small> by clicking on the fontawesome icon <button class="btn btn-default btn-xs" onclick="copyText()"><i class="fas fa-copy"></i></button>.
How to do this ?
(function($) {
function copyText() {
var text = document.getElementById("copy-to-clipboard");
text.select();
document.execCommand("copy");
alert("Copied the text: " + text.value);
}
})(jQuery);
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="message-donation text-justify">
<div>Si le contenu de ce groupe vous plait, vous pouvez faire un don à son l'auteur en Bitcoin (BTC).</div>
<div class="h3"><i class="fab fa-bitcoin fa-lg btc"></i> Adresse BTC :</div>
{{ content.field_groupe_donation }}
<small type="text" id="copy-to-clipboard">{{ group.field_groupe_donation.value }}</small>
<button class="btn btn-default btn-xs" onclick="copyText()"><i class="fas fa-copy"></i></button>
<div class="mt-3 text-center">
<b>Comment ça marche ?</b>
</div>
</div>
Here is the result :
It does not work.
After modifying your code, I propose to create the "copyText" function in this way.
function copyText() {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($("#copy-to-clipboard").text()).select();
document.execCommand("copy");
$temp.remove();
alert('Copied');
}
The instruction document.execCommand("copy"); allows you to copy all the elements of the DOM you have selected using the .select() function.
You can use the clipboard API for this. Please note that this requires your site to run in a secure context (https or localhost).
Example:
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('bar').addEventListener('click', () => {
if (window.isSecureContext && 'clipboard' in navigator) {
navigator.clipboard.writeText(document.getElementById('foo').textContent);
} else {
console.error(`Clipboard API requires secure context or your browser doesn't support clipboard API`);
}
})
})
<small id="foo">This text should be in your clipboard after clicking the copy button</small>
<br />
<button id="bar" type="button">copy</button>
<br />
<textarea placeholder="try pasting here after clicking copy button" cols="60" rows="3"></textarea>
As with most things, in 2020 you want to be using the browser API and not jQuery.

How can I create a loop for Chat Bubbles?

I want to develop a loop for chat bubbles. Every time I write a message, a bubble should be created and be on the right. When the chat partner replies, the message should be on the left in the bubble. How can I develop this loop?
My current code is this one:
<div class="Webview">
<div class="message_container" id="myForm"></div>
<form class="send_container">
<input id="textField" type="text">
<p>
<input type="button" id="theButton" value="Nachricht absenden!" onclick="document.getElementById('myForm').innerHTML=document.getElementById('textField').value" />
</p>
<h3>
<div id="div"></div>
</h3>
</form>
</div>
OK, it is not add messages to the DOM in loops, but just add message on Enter on the trigger that sending the message.
If you want to add value from Text Field such as text input,
You probably want to do two steps:
Getting the value from the input
Inject the value into a balloon template (html) and then into the DOM.
Then, you should add Javascript scope into your html or just include js file that contain the following function:
function addMessage() {
// Add XSS validation
const $messages = document.getElementById('myForm');
const $textElement = document.getElementById('textField');
const newMessage = '<div class="message-balloon">' + $textElement.value + '</div>';
$messages.innerHTML += newMessage;
return false;
}
<input type="button" id="theButton" value="Nachricht absenden!" onclick="addMessage()" />
In jQuery it will be like this (in the js scope of course):
$("#theButton").off('click').on('click', function() {
e.preventDefault();
const $messages = $('#myForm');
const $textElement = $('#textField');
const newMessage = '<div class="message-balloon">' + $textElement.value + '</div>';
$messages.html += newMessage;
return false;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="button" id="theButton" value="Nachricht absenden!" />
Hope it helps :)
Good luck

Opening an html to a div with XMLHttpRequest causes sync error

I am trying to load a htm to a div in another htm but I keep getting the error below:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Here is my scenario:
First.html (html)
<div id="selectedPage"></div>
First.html (script)
<script>
function loadHTML2Div(htmlPage){
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
$("#selectedPage").html(xmlHttp.responseText);
}
};
xmlHttp.open("GET", htmlPage, true); // true for asynchronous
xmlHttp.send(null);
}
$(document).ready(function(){
loadHTML2Div("Second.htm");
});
</script>
Second.htm (html)
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class='jumbotron'>
<span>Verifique as datas disponíveis e agende seu evento.</span>
</div>
<div data-provide="calendar" id="calendar"></div>
</div>
</div>
</div>
<div class="modal fade" id="preReservaModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="modaldate"></h4>
</div>
<div class="modal-body ">
<div class="form-group">
<label for="exampleInputNome">Nome Completo</label>
<input class="form-control" id="exampleInputNome" placeholder="Digite seu nome completo" type="nome">
<br/>
<label for="exampleInputEmail1">Email</label>
<input class="form-control" id="exampleInputEmail1" placeholder="Digite seu email" type="email">
<br/>
<label for="exampleInputTelefone">Telefone para contato</label>
<input class="form-control" id="exampleInputTelefone" placeholder="Digite seu telefone para contato" type="telefone">
<br/>
<label for="exampleInputPlano">Pacote</label>
<select class="input-large form-control">
<option value="" selected="selected">Selecione um pacote</option>
<option value="DI" >Diamante</option>
<option value="ES">Esmeralda</option>
<option value="RU">Rubi</option>
</select>
</div>
</div>
<div class="modal-footer">
Fechar
Confirmar
</div>
</div>
</div>
</div>
<script src='bootstrap/js/bootstrap-combobox.js'></script>
<script src="bootstrap/js/bootstrap-year-calendar.js"></script>
</body>
I also have a navbar-nav from bootstrap on top of my First.htm for the navigation, and I also have a Third.htm and Fourth.htm that can be opened when the navbar is clicked. I use loadHTML2Div for switching between the contents of the . I don't know if this is the best approach.
As far as I searched this Synchronous XMLHttpRequest error, I would fix it by using ajax async call. I tried using xmlHttpRequest as mentioned above and I also tried using .ajax async
function loadHTML2Div(htmlPage){
$.ajax({
async: true,
type: "GET",
url: htmlPage,
success: function(data){
$("#selectedPage").html(data);
}
});
}
But I got the same error.
Please advise me how can I avoid this sync error. As you can see I tried different ways before elaborating this question.
If you need more information please let me know.
Edited
I kept testing and I fixed this error in some htmls. The problem was I was adding the Jquery and the bootstrap js in both First and Third html for example.
I removed the script declaration from the third.htm for example and left only the declaration in the 'upper' html (First.html). So somehow declaring it on both files was causing me the error.
Unfortunatelly, I still have a problem with the Second.htm which I copied to this question. This htm has a calendar and a bootstrap combobox. If I delete them from the Second.htm and write them in the First.htm, it doesn't work.
<script src='bootstrap/js/bootstrap-combobox.js'></script>
<script src="bootstrap/js/bootstrap-year-calendar.js"></script>
I also have some scripts for the clickDay and setMinDate in the Second.htm as shown below which fail if I remove the scripts declaration and move it to the upper First.htm.
$('#calendar').data('calendar').setMinDate(todayDt);
So it seems to me my lack of knowledge is leading me to this problem. It is probably very simple to solve it, if someone could help me i will appreciate.
set your the ajax attribute async to false
$.ajax({
async: false,
type: "GET",
url: htmlPage,
success: function(data){
$("#selectedPage").html(data);
}
});
I finally figured out what the problem was.
I moved the scripts declaration from Second.htm to First.htm
<script src='bootstrap/js/bootstrap-combobox.js'></script>
<script src="bootstrap/js/bootstrap-year-calendar.js"></script>
Then I changed my html from
<div data-provide="calendar" id="calendar"></div>
to
<div id="calendar"></div>
and created the calendar in the ready function
<script>
$( document ).ready(function() {
$('#calendar').calendar();
});
</script>
As I am a newbie in web development, I know this is still not the best way to structure my website navigation using navbar from bootstrap. For now I will leave this way.
My goal is to have my first htm with the navbar and the contents from each navbar item in different htms (as I have now), but I want the url to change as I click each item:
www.mywebsite.com/First.htm
www.mywebsite.com/Second.htm
www.mywebsite.com/Third.htm
And right now I only have
www.mywebsite.com/First.htm
Where all my scripts are included in the First.htm. It means I am loading the calendar.js even if I don't open the calendars page.
Well, I hope I will help someone with my question/answer in the future even though it is a little confusing. I promise next time I will have more knowledge.

Button - Voucher onclick

Hello community need some assistance,
I am trying since couple days to add into exit-popup template one php button which onlick interacts with less template and adds Voucher code into the cart.
I got no success yet, if someone could assist me. Could possibly award somehow :)
Theoreticly its could even be possible to inject into sql onlick instead of injecting to element.
Github Original cart_footer.tpl
Github Original Voucher.tpl
Platform: shopwaredemo.de/
and any item to cart, so you can see elemnts
So far i have done:
Form:
<form method="post" action="{url action='addVoucher' sTargetAction=$sTargetAction}">
<div class="popupbanner">
<a href="#" class="myButton" clickon="copyToClipboard('#p2');ImportVoucher('FREE16')" >
<div class="close-exit-intent" title="Click to Copy" type="submit">
<input id="p2" class="p22" value="FREE16" />
<p id="p2" class="p22">FREE16</p>
</div> </a>
<p class="click2copy">Click to Copy ↗</p>
<p>No thanks</p>
</div>
</form>
Copytoclipboard js
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
ImportVoucher js
function ImportVoucher(element) {
$('input[type=p2]').click(function(ev) {
ev.preventDefault();
$(this).siblings('input[type=p2]').removeClass('selected');
$(this).addClass('selected');
$('#sVoucher').val($('.selected').val());
$temp.remove();
}
added id into cart-footer
<input type="text" class="add-voucher--field is--medium block" id="sVoucher" name="sVoucher" placeholder="{"{s name='CheckoutFooterAddVoucherLabelInline'}{/s}"|escape}" />

Loading a form action inside a div

I have a form and I want to load the results from it into a div. I've already searched some topics about this and I thought that this one jquery submit form and then show results in an existing div would work but it doesn't.
This is my code so far:
<script type="text/javascript"> $('#form').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#test').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting }); </script>
<DIV id="test"></DIV>
<FORM id="form" name="pcc" method="post" action="http://wl.breedbandwinkel.nl/postcodecheck" onSubmit="return validatePcc(this);">
<div class="one_third firstcols">
<H4>Ik ben op zoek naar:</H4>
<DIV class="ff"><INPUT type="radio" class="pccrad radio" name="sub" value="alles-in-een-pakketten" id="pcc-alles-in-een-pakketten" onclick="$('#pcc-no').hide(); $('#pcc-fpcon').css('visibility', 'visible'); if($('#pcg').val() == '') $('#pcg').focus();"><LABEL class="left pcm" for="pcc-alles-in-een-pakketten" onmouseover="mpopup('Alles-in-één pakketten','Extra voordelig pakket met internet, digitale telefonie en/of digitale televisie.');" onmouseout="kill();">Alles-in-één pakketten</LABEL></DIV> <DIV class="ff"><INPUT type="radio" class="pccrad radio" name="sub" value="internet" id="pcc-internet" onclick="$('#pcc-no').hide(); $('#pcc-fpcon').css('visibility', 'visible'); if($('#pcg').val() == '') $('#pcg').focus();"><LABEL class="left pcm" for="pcc-internet" onmouseover="mpopup('Internet','Altijd supersnel onbeperkt online tegen een vast bedrag per maand.');" onmouseout="kill();">Internet</LABEL></DIV> <DIV class="ff"><INPUT type="radio" class="pccrad radio" name="sub" value="digitale-televisie" id="pcc-digitale-televisie" onclick="$('#pcc-no').hide(); $('#pcc-fpcon').css('visibility', 'visible'); if($('#pcg').val() == '') $('#pcg').focus();"><LABEL class="left pcm" for="pcc-digitale-televisie" onmouseover="mpopup('Digitale Televisie','Geniet van haarscherp digitaal beeld en geluid inclusief de gratis digitale programmagids.');" onmouseout="kill();">Digitale Televisie</LABEL></DIV>
</div><!-- end .one_third -->
<div class="one_third">
<H4>Mijn postcode en huisnummer zijn:</H4>
<TABLE border="0" cellspacing="0" cellpadding="0">
<TR>
<TD height="14" colspan="2">Postcode</TD>
<TD>Huisnr.</TD>
</TR>
<TR>
<TD width="51"><INPUT type="text" class="text" maxlength="4" size="5" value="" name="pcg" id="pcg" onKeyUp="autoTab(event,this,4,pcl);" onFocus="chBg(pcc,'pcg');" onBlur="chBg(pcc,'reset');" style="width: 41px;"></TD>
<TD width="46"><INPUT type="text" class="text" maxlength="2" size="2" value="" name="pcl" id="pcl" onKeyUp="autoTab(event,this,2,hn);" onKeyDown="backSpace(event,this,pcg);" onFocus="chBg(pcc,'pcl');" onBlur="chBg(pcc,'reset'); upperCase(event,this);" style="width: 26px;"></TD>
<TD width="36"><INPUT type="text" class="text" maxlength="6" size="4" value="" name="hn" id="hn" onKeyDown="backSpace(event,this,pcl);" onFocus="chBg(pcc,'hn');" onBlur="chBg(pcc,'reset');" style="width: 36px;"></TD>
</TR>
</TABLE>
<U class="dot small" onmouseover="popup('Waarom mijn postcode invullen?','Om te kunnen controleren welke abonnementen op uw adres leverbaar zijn hebben wij uw postcode en huisnummer nodig.<br>Uiteraard respecteren wij uw privacy. Deze gegevens worden niet opgeslagen.');" onmouseout="kill();">
Waarom mijn postcode invullen?</U>
</div><!-- end .one_third -->
<div class="one_third lastcols">
<INPUT type="submit" name="submit" value="Vergelijk de aanbiedingen op uw adres" class="button">
</div><!-- end .one_third -->
</FORM>
So I figured out that this is not working. I would really like to show the results from the action url (http://wl.breedbandwinkel.nl/postcodecheck) into <div id="test">.
Currently I'm doing this within an iframe but that just doesn't look "professional".
I hope I gave enough information, if not let met know.
Most importantly, if your Web page is not running from within http://wl.breedbandwinkel.nl, the AJAX call probably won't run at all due to most every browser disabling cross-site scripting. You can't make an AJAX request to foo.com from a page served from bar.com. To circumvent this, what I usually do is write a file such as "bar.com/ajaxActions.php" and then use that PHP script to make either the GET or POST request to the foreign site. Once it retrieves the result, I simply print that result to the standard output, which then becomes the result of your AJAX request.
The other thing I would do is ditch the "method" and "action" attributes in your <form> tag and put those in the AJAX request you're trying to write with jQuery. Use an onClick() listener in your submit button instead, as such:
<INPUT type="submit" name="submit" onClick="doAjaxRequest()" value="Vergelijk de aanbiedingen op uw adres" class="button">
Then in that function, use the code you already had in place for starters:
<script type="text/javascript">
function doAjaxRequest() {
$.ajax({ // create an AJAX call...
data: $("#form").serialize(), // get the form data
type: GET, // GET or POST
url: "ajaxActions.php", // the file to call -- postcodecheck if you're on that same domain, otherwise ajaxActions.php
success: function(response) { // on success..
$('#test').html(response); // update the DIV
}
});
}
Finally, if you're not on the same domain, I will leave it to you to find out the PHP code for the GET request (use file_get_contents()) or the POST request (use cURL). Or if you can't use PHP, then use your back-end language of choice. In PHP, assuming your post code checker accepted a GET request, your ajaxActions.php file would look something like this:
$response = file_get_contents("http://wl.breedbandwinkel.nl/postcodecheck?pcg=" . $_GET["pcg"] . "&pcl=" . $_GET["pcl"] . "&hn=" . $_GET["hn"] );
print $reponse;