How to Click or trigger <a href="javascript:viewPage('ABC');> with DOM - function

I'm a beginner, tried to click the link with DOM but didn't worked. how can I click or trigger the function? and why didn't that work?
<li id="viewPage">viewPage
document.getElementById("viewPage").click()
function viewPage(Name,Number){
$("#ViewPage li").removeClass("active");
$("#"+Name).addClass("active");
$("#ViewPage").load(
Name+".asp",
{
Number : Number
},
function( response, status, xhr ) {
if ( status == "error" ) {
var msg = "there was an error: ";
$( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
}
});
}

Since you don't seem to mind using jquery in the rest of your code, here is an easy way to get the click using jquery:
$('#viewPage').click(function() {
console.log('Now your click function is working');
});
function viewPage1(Name, Number) {
$("#ViewPage1 li").removeClass("active");
$("#" + Name).addClass("active");
$("#ViewPage1").load(
Name + ".asp", {
Number: Number
},
function(response, status, xhr) {
if (status == "error") {
var msg = "there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li id="viewPage">viewPage1

Related

Chrome Extension chrome.storage.local.set value is not passed from content script to Background Script

I am trying to pass the Input value from content script to background script and persist this value until changed in the extension.
However, the value is saved on the content script but it is not available in the background script.
Here is the Extension HTML:
<input type="text" class="InputControl form-control" id="Key"/>
<button class="save-to-key" id="saveButton" type="button">Save</button>
Here is content script that triggers based on the button click:
//use strict';
var KeyInput = document.getElementById("Key");
var SaveButton = document.getElementById("saveButton");
function SaveButtonclick() {
if(KeyInput.value!==""){
chrome.storage.local.set({'key': KeyInput.value}, function() {
chrome.runtime.sendMessage({messageType:"KeyData",Key:KeyInput.value});
console.log(" click event value " + KeyInput.value);
alert("Value currently is set by script " + KeyInput.value);
//window.close();
if(chrome.runtime.lastError) {
console.error(
"Error setting'key to " + JSON.stringify(KeyInput.value) +
": " + chrome.runtime.lastError.message
);
}
});
chrome.storage.local.get("Key").then((result) => {
console.log("extracted from storage" + result.Key);// this is undefined for some reason
});
}
}
//document.addEventListener('DOMContentLoaded', SaveButtonclick , false);
SaveButton.addEventListener('click',SaveButtonclick,false);
chrome.runtime.onSuspend.addListener(() => {
console.log("Unloading.");
});
Here is the background script:
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if(message.messageType=="KeyData"){
chrome.storage.local.set({"Key":message.key});
console.log("Value currently is from message listeners "+message.key);
sendResponse({'message':"KeyDataSavedSuccessfully"})
}
});
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
id: "1",
title: "Save!",
contexts:["selection"] // ContextType
});
});
var KeyValue = function(word){
var query = word.selectionText;
var Key;
chrome.storage.local.get("Key").then((result) => {
Key=result.Key;
});
console.log("Value currently is Main Script and get defaultvalues function is" + Key);
chrome.tabs.create({url: "https://example.com/v1/test?sid="+query+"&Key="+Key+"&test=true"});
};
chrome.contextMenus.onClicked.addListener(KeyValue);
Hope you can help.
I noticed where i was going wrong! I am not waiting for the result so the value is undefined.
I changed the extension script here:
//use strict';
var KeyInput = document.getElementById("Key");
var SaveButton = document.getElementById("saveButton");
function SaveButtonclick() {
if(KeyInput.value!==""){
chrome.storage.local.set({'key': KeyInput.value}, function() {
chrome.runtime.sendMessage({messageType:"KeyData",Key:KeyInput.value},function (response) {
console.log("message sent to backgroud "+JSON.stringify(response));
});
console.log(" click event value " + KeyInput.value);
alert("Value currently is set by script " + KeyInput.value);
//window.close();
if(chrome.runtime.lastError) {
console.error(
"Error setting key to " + JSON.stringify(KeyInput.value) +
": " + chrome.runtime.lastError.message
);
}
});
chrome.storage.local.get("Key").then((result) => {
console.log("extracted from storage" + result.Key);// this is undefined for some reason
});
}
}
//document.addEventListener('DOMContentLoaded', SaveButtonclick , false);
SaveButton.addEventListener('click',SaveButtonclick,false);
chrome.runtime.onSuspend.addListener(() => {
console.log("Unloading.");
});
I changed this part in the background Script:
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if(message.messageType=="KeyData"){
var Keyvaluetosave=message.Key;
chrome.storage.local.set({"Key":Keyvaluetosave});
console.log("Value currently is from message listeners "+Keyvaluetosave);
sendResponse({'message':"KeyDataSavedSuccessfully"})
}
});
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
id: "1",
title: "Save!",
contexts:["selection"] // ContextType
});
});
var KeyValue = function(word){
var query = word.selectionText;
var Key;
chrome.storage.local.get("Key").then((result) => {
Key=result.Key;
console.log("Value currently is Main Script and get defaultvalues function is" + Key);
chrome.tabs.create({url: "https://example.com/v1/test?sid="+query+"&Key="+Key+"&test=true"});
});
};
I did type in some part here on the... but this does fix the issue .. value is passed. If any one can improve this then please do so . Thank you so much...!

Card payment error 508 -Realex payments error number: 61,754

i am using realex payment with iframe
i can load the payment page correctly, but as soon as i hit 'Pay Now'
it return Error: 508
Message: An error has occurred processing your request. Please contact the merchant whose goods or services you are purchasing quoting the following error number: 61,754
(most of time it return correct response string either successful and declined) but sometimes it return above error code)
any idea what is mean and how to solve this issue?
<script type='text/javascript'>
function iRedirect(redirectUrl, arg, value) {
console.log(redirectUrl);
try {
var form = $('<form action="' + redirectUrl + '" method="post">' +
'<input type="hidden" name="' + arg + '" value="' + value + '"></input>' + '</form>');
$('body').append(form);
console.log(form);
$(form).submit();
}
catch (e) {
alert(e.message);
}
}
function displayMessage(evt)
{
var message;
try {
var iOrigin = '<%=ConfigurationManager.AppSettings["RealexResponseDomain"] %>';
if (evt.origin == iOrigin) {
message = evt.data.toString();
console.log(message);
if (message.indexOf("Error") == 0) {
var ErrorJsonStr = message.toString().split(":");
var ErrorJsonStr1 = ErrorJsonStr[1].split("<BR>");
var reDirectPath = "{\"" + ErrorJsonStr[0] + "\"" + ":" + "\"" + ErrorJsonStr1[0] + "\"" + "," + "\"" + ErrorJsonStr1[1] + "\"" + ":" + "\"" + ErrorJsonStr[2] + "\"" + "}";
iRedirect("Response.aspx", "JsonStr", encodeURIComponent(reDirectPath));
}
else {
if (isJson(message) == true) {
var message1 = JSON.parse(message);
//alert(message1);
console.log(message1);
if (message1.hasOwnProperty('pas_uuid')) {
iRedirect("Response.aspx", "JsonStr", encodeURIComponent(message.toString()));
}
else {
//check if this transaction is already exist
//do redirect
//alert("not pas_uuid" + message1);
console.log("not pas_uuid" + message1);
}
}
}
//get message and check result
}
else {
console.log("not data");
}
}
catch (err) {
console.log(err.message);
}
}
function isJson(str) {
try {
JSON.parse(str);
}
catch (e)
{
console.log(e.message);
return false;
}
return true;
}
if (window.addEventListener) {
// For standards-compliant web browsers
window.addEventListener("message", displayMessage, false);
}
else {
window.attachEvent("onmessage", displayMessage);
}
</script>
There are two major scenarios where this message may be displayed on the HPP.
There was a temporary issue with the HPP Sandbox environment.
The Merchant ID and Account you are using has 3D Secure 1 enabled, but you used a non-3D Secure enabled test card.
If you think it wasn't either of these issues, please provide our Support Team with an example Order ID of a transaction where this occurred and they will be able to look at the logs in more detail.

Token Input Ondelete is not working

I have a form where i have used token input plugin to select multiple items from a predefined list. However Ondelete function is not working.
<script type="text/javascript">
$(document).ready(function() {
var1_ids = '<?php echo $records[0]['team_member']?>';
$("#team_member").tokenInput("<?php echo base_url(); ?>staff_activity/get_members", {
theme: "facebook",
prePopulate: [<?php echo $show1; ?>],
resultsFormatter: function(item){ return "<li>" + " " + "<div style='display: inline-block; padding-left: 5px;'><div class='full_name'>" + item.first_name + "</div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.first_name + "</p></li>" },
onAdd: function (item) {
var1_ids = var1_ids + item.staff_id + ',';
$('#team_member_ids').val(var1_ids);
},
onDelete: function (item) {
var1_ids = var1_ids.replace(item.staff_id+',','');
$('#team_member_ids').val(var1_ids);
}
});
});
</script>
where var_dump($records[0]['team_member']?>); is string(11) ",900,4,979,"

How to create function for Reset Form with use kendo element and other HTML element

I want create function for reset form with use kendo element and other HTML element. I create this function:
function resetForm() {
var formName = $(this).data("form");
var form = $(formName);
if (form) {
//orginal reset
form.trigger("reset");
//custom reset
$(formName + " input").each(function () {
var cb = $(this).data("kendoDropDownList");
if (cb) {
cb.value("");
cb.text("");
}
});
}
}
Not work correctly!
I found this way:
if (form) {
//custom reset
$(formName + " input[data-role='dropdownlist']").each(function () {
var item = $(this).data("kendoDropDownList");
if (item && $(this).attr('id') != 'AgeType' && $(this).attr('id') != 'AllAnyType') {
item.value("");
item.text("");
}
});
$(formName + " input.k-textbox").each(function () {
$(this).val("");
});
$(formName + " input[data-role='numerictextbox']").not("#TopNumber").each(function () {
var item = $(this).data("kendoNumericTextBox");
if (item) {
item.value("");
}
});
$(formName + " textarea").each(function () {
$(this).val("");
});
$(formName + " :checkbox").each(function () {
this.checked = !this.checked;
});
$(formName + " input[type=text]").each(function () {
$(this).val("");
});
}

Trouble with chrome.extension.sendRequest();

contenescript.js
var someText = 'some text to show1';
chrome.extension.sendRequest({'action' : 'openMyTab','text': someText});
background.html
function onRequest(request, sender, callback) {
if (request.action == 'openMyTab') {
alert(" Inside onRequest with " + request.text);
}
};
chrome.extension.onRequest.addListener(onRequest);
This works fine. And as expected gives an alert message.
But on changing the contentscript.js to something like this.
Wordlistonilne.Selector.dblClick = function(){
var st = Wordlistonilne.Selector.getSelected();
if(st!=''){
myMethod('openMyTab',st);
}
}
function myMethod(action,message){
alert("myMethod : action = " + action + "message = " + message);
chrome.extension.sendRequest({'action' : action,'text': message});
}
$(document).ready(function(){
$(document).bind("dblclick", Wordlistonilne.Selector.dblClick);
});
I get the alert with the action and message. But the chrome.extension.sendRequest doesnt seem to work.
F1 F1 please help me out