Get element from pop up - javascript

I'm trying to make an application to change SSID and password more easily using webview with react native. But when i get to apply the changes one popup shows up . I don't know how to get the id from popup's button. I'am using getelementbyid for other elements.
Edit: i found this post in stack where he changes the script inside a button. But i don't know how to do this when the script is inside a tag :((((
Button:
<button id="btnApplySubmit" name="btnApplySubmit" type="button" class="ApplyButtoncss buttonwidth_100px" onclick="ApplySubmit();">
<script>
document.write(cfg_wlancfgother_language['amp_wlancfg_apply']);
</script>Apply
</button>

Related

How to hide CSS Elements by clicking a button?

I am building a Chrome Web Extension that hides parts of Youtube's home page at the click of a button.
I am trying to hide CSS elements after the webpage loads after clicking a button on my Chrome extension's popup.
I am not able to use inline CSS and must use javascript due to chrome's security protocols.
when I click the button on the popup, I received the following error: "Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')"
HTML:
<button id="hideRecommended">Hide Recommended</button>
Javascript:
let homePage = document.querySelector(".style-scope.ytd-rich-grid-renderer#primary");
document.querySelector(".hideRecommended").addEventListener("click",showHideHomePage);
function showHideHomePage(){
homePage.style.display="none";
}
I am not sure what I am doing wrong. Any input would be GREATLY appreciated. Thank you for reading
Since you are define the button by id as follows
<button id="hideRecommended">Hide Recommended</button>
So change
document.querySelector(".hideRecommended").addEventListener("click",showHideHomePage);
To
document.querySelector("#hideRecommended").addEventListener("click",showHideHomePage);
Note:
.hideRecommended measn select by class
#hideRecommended means
select by id

How can I select this element with javascript?

I am trying to write an applescript application that logs into a website upon launching. So far I can successfully open Chrome, load the web page into the active tab, select and input the password, but I cannot click the submit button.
Below is the element on the page:
<button type="submit" class="btn btn--ac" alt="Login"
title="Login" tabindex="6"><i aria-hidden="true"
class="lush lush-locked"></i> Login</button>
My skill level in javascript is little to none, yet I cannot find a way to successfully select this item and click it. I have tried already using the TagName and ClassName but it does not work, perhaps my syntax is incorrect. Is there a way to do this without a ID type?
I have tried:
execute front window's active tab javascript
"document.getElementByClassName('btn, btn--ac').click()"
execute front window's active tab javascript
"document.getElementByTagName('button').click()"
I should note this script runs in Google Chrome.
Thanks for any help in advance.
First of all you're using a wrong function. It should be
document.getElementsByClassName
Try using: (Assuming the Submit button is the only button with class btn)
document.getElementsByClassName('btn')[0].click();
Here's basic definition of the function from Mozilla:
document.getElementsByClassName():
Returns an array-like object of all child elements which have all of
the given class names.
Hence, you get a list of elements. Hence, you select the first element in it (using the 0 as index), and then click on it.
The correct syntax in plain js to select an element by his class is:
document.getElementsByClassName('btn--ac');
With this you'll get an array with all elements with the class 'btw--ac'. In your case try this:
document.getElementsByClassName('btn--ac')[0].click();

Dynamic Confirmation Message on a confirm.html

I am trying to create a Javascript function to display a dynamic confirmation message, that will appear on a confirm.html page. It needs to be in an external Javascript file so that it can be used on a variety of pages. I've tried a variety of things but I just cant quite get it to work correctly. I'm trying to do it with only Javascript.
This is what I have currently, after doing some research
This is button I'm using to call the function
<input type="button" value="Remove" onclick="dynamicMessage('This product has been deleted')">
and the current function I'm using is
function dynamicMessage(argument)
{
var test = window.open("./confirm.html","_self");
test.document.write("test");
test.document.close();
}
Obviously, the dynamic content isn't added in yet, but if my thinking is correct, it should just be adding the argument somewhere in the long string of html I need to add to create the page. The "test is just do see what happens when calling the function.
What I want it to do is, write the "test" to the new window of confirm.html, but instead it overwrites the current window. But if I only call window.open, it opens to the correct window. It is the document.write part that is throwing me off.
I'm not sure if I'm far off base on my thinking, or if its just a simple mistake I'm missing after hours of looking at this code. Any Ideas?
I think I need to clarify what I am trying to do. I am trying to click a button, in this case a remove button, then open up the page confirm.html, edit the content in confirm.html with the argument, and have the current page now be confirm.html. What currently happens is one of two things either the current document is edited if the "_self" tag is placed, or the html page is open and thus an about_blank url.
Hope i understood your question | DEMO
Since you are using document.write method it will overwrite contents of your html page
function dynamicMessage(argument)
{
var test = window.open("./confirm.html","_blank");
test.document.write(argument);
setTimeout(function(){test.close()},2000); // after 2 sec it will close
}

How do I get a button to trigger a javascript function?

I have a C#/.NET web application I am working on. On one of the pages I have a table of values generated from a database. I need each value to be clickable so that when you click a value it filters data in a separate table next to it.
So what I decided to do was to make each value into a button:
<input type="button" id="exampleID" class="exampleClass" value="#Model.Data.Value1" />
In my Javascript I have this:
$(".exampleClass").click(function () {...
The code inside the function isn't relevant to the question because it isn't getting called when I click the button. Each button has a unique ID that I am using in my function and I gave them each the same class so that I can catch when any of them are called and then use their unique ID to determine which was clicked. I have set a breakpoint inside the function using Firebug but it's not getting tripped when I click the button. I am stumped as to why this isn't working.
Could be any number of things: are you attaching the click event in the ready method? Is jQuery even loaded on the page? Have you tried refining the selector? For example, $('input.exampleClass').click(). It has to be some dumb mistake.

Trying to retrieve yahoo weather using jquery / php / xml

Whats wrong with this function?
function yahooWeather(){
var loadPage = 'yahooweather.php?p='+ $("#myCity").val();
$("#yahoo").html('<img src="loading.gif" align="absmiddle">');
$("#yahoo").load(loadPage);
}
Is there another way to write this function. Im unsure if its able to read the .val required, tho i know it is set as i used it in a previous function to test that it was being set, so im thinking its maybe my load call.
http://www.wetterkanal.tv/
This is the page. This function once called by clicking the button, should get the value set by the "select city" option then load the weather in a div below. I have set the css to this div as green so i know it loads. I also know that my php script works as if i test it by going to the following:
http://wetterkanal.tv/yahooweather.php?p=ASXX0001
it pulls the weather in correctly. Please help!
Your problem is that the button element will reload the page when the button is clicked.
You need to change your onclick attribute to onclick="yahooWeather(); return false;".

Categories

Resources