Calling Select Tag from URL - html

I have a webpage with a <select> tag called dropDown with selectable options 'OptionA', 'OptionB' and 'OptionC'.
It is possible for me to link to the webpage and call one of the options from the URL?
For example: smaple.aspx?dropDown=OptionB

You can get the GET parameter with JavaScript
let params = new URLSearchParams(document.location.search);
let dropDownValue = params.get("dropDown");
then change the select value with JavaScript(assume the select element has a id called a-dropdown)
document.getElementById('a-dropdown').value = dropDownValue;

Related

Two way binded data appears as string in Polymer

I am trying to render polymer template using below code,
const shadowRoot = this.attachShadow({mode: 'open'});
const htmlTemplate = importDoc.querySelector('template');
shadowRoot.innerHTML = htmlTemplate.innerHTML;
But this renders two way binded data also as a string instead of showing the binded value e.g
<h1 id ="contactFooter">{{localize('_testVal')}}</h1>
is displayed as it is do anyone have any idea? Two way binding is just example it renders everything like this.
To use a <template> tag you should use importNode on the content.
e.g.
var clone = document.importNode(htmlTemplate.content, true);
shadowRoot.appendChild(clone);
// note that you will need to clear the shadowRoot if you do rerenderings
// OR you could try
shadowRoot.innerHTML = htmlTemplate.content;
see more details here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template

Get href from an element found by ID - Python - Selenium

This is my code:
dispatch_button = browser.find_elements_by_xpath("//*[contains(#id, 'alarm')]")
href = dispatch_button.get_attribute('href')
print(href)
This is the HTML i'm working with:
Dispatch
The ID and href both contain a number that changes which is why i'm finding it using the partial ID.
I'm completely stumped as i can't see why I'm getting this error:
href = dispatch_button.get_attribute('href')
AttributeError: 'list' object has no attribute 'get_attribute'
I'm trying to locate the dispatch_button by its partial ID, and then use its href.
If you want to get single WebElement you should use find_element_by_xpath() instead of find_elements_by_xpath():
dispatch_button = browser.find_element_by_xpath("//*[contains(#id, 'alarm')]")
href = dispatch_button.get_attribute('href')
or if you want to handle multiple elements matched by specified selector:
dispatch_buttons = browser.find_elements_by_xpath("//*[contains(#id, 'alarm')]")
hrefs = [dispatch_button.get_attribute('href') for dispatch_button in dispatch_buttons]
Also you can try to locate required anchor by link_text:
dispatch_button = browser.find_element_by_link_text("Dispatch")

How to set parameter and its value to HREF dynamic using javascript

I have a link like following
<a id="dynamicLink" href="http://www.w3schools.com?userName=test">Visit W3Schools</a>
I would like to change the value of userName from test to test1.
How to do that using javascript?
could someone help me on this?
I suggest using a library to work with URIs. It will provide some consistency. Here is an example using URI.js:
// Get our <a> element
var l = document.getElementById('dynamicLink');
// Use URI.js to work with the URI
// http://medialize.github.io/URI.js/
var uri = URI(l.href);
// Get the query string as an object
var qs = uri.query(true);
// Change our value
qs.userName = 'test1'
// Update the URI object
uri.query(qs);
// Set our new HREF on the <a> element
l.href = uri;
<script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.15.2/URI.min.js"></script>
<a id="dynamicLink" href="http://www.w3schools.com?userName=test&someOtherKey=val">Visit W3Schools</a>
Try this:
document.getElementById("dynamicLink").href.replace("userName", "test1");
This should change the value of userName in href to test1

angularjs save rendered values in html in a variable

I hope someone can help me with this, It's a strange question maybe as I didn't find an answer online.
I call the database and retrieve a list (in json) of items.
Then in angularjs,I render this list by extracting relevant pieces of data(name,age,etc) and show it properly in a table as a list of rows.
I have then an edit button that takes me to another page where I want to put a dropdown list.
What I want to know if is possible to add to that dropdown list the rendered list I previously created in my previous page.
is it possible to save the previously rendered list in a variable and then use that variable in the dropdown?
thank you
You could store the list within a controller and make this data availablte to this dropdown, I think.
Instead of trying to query for the list, add the list to the template, get the list from the template and render somewhere else, I'd suggest query for the list, save the list in a service , and then when you want to use that list again, get it from the service. Something like:
service:
var services = angular.module('services');
services.factory('getListService',['$http',function($http){
var getListOfStuff = function(){
//call to database
return //your json
};
var extractNameAgeEtc = function(){
var myListOfStuff = //get list of stuff from $http or database
var myListOfNameAgeEtc = //make a list of tuples or {name,age,etc} objects
return myListOfNameAgeEtc;
};
return {
extractNameAgeEtc : extractNameAgeEtc
};
}]);
controllers:
angular.module('controllers',['services']);
var controllersModule = angular.module('controllers');
controllersModule.controller('tableRenderController',['getListService','$scope',function(getListService,$scope){
//use this with your table rendering template, probably with ng-repeat
$scope.MyTableValue = getListService.extractNameAgeEtc();
}]);
controllersModule.controller('dropdownRenderController',['getListService','$scope',function(getListService,$scope){
//use this with your dropdown rendering template, probably with ng-repeat
$scope.MyDropDownValue = getListService.extractNameAgeEtc();
}]);

how can i know if an anchor link is clicked or not?

I want to know if an anchor link is clicked.
I add anchor links dynamically and set ids with their name file but i dont know how amoutn the number of the cell "clicked" in my Spreadshett.
For ex: the id of file "test.pdf" --> test;
in spreadsheet:
ex:
ColumA <namefile>: test.pdf
ColumB <linkfile>: https://docs.google.com/document/d/1PiMj.....jramcs
ColumC <cliked>: 1
I'm specting that if i clicked my anchor my function could know which anchor is cliked and amount " 1 " in colum C in the ppropriate row.
var html = app.createAnchor(nf, hf).setId(nf);
I am trying to make something like:
var html = app.createAnchor(nf, hf).setId(nf).addClickHandler(app.createServerHandler("sumDoc").addCallbackElement(flexTableDoc));
¿But how i know which anchor is cliked in the function sumDoc?
I think you can get that using client handlers and a textbox (this last one can be visible or not).
var clickedItem = app.createTextBox().setName('clickedItem')
On each anchor you add a clickHandler like this
var handler = app.createClientHandler().forTargets(clickedItem).setText(Anchorname);
anchor.addClickHandler(handler)
and in the server handler you will get the textBoxValue with
var clickedItem = e.parameter.clickedItem;
if you want a more accurate code you should provide the code you use to create the UI with the anchors
This is also possible and easy, format your anchor like you said.
var html = app.createAnchor(nf, hf).setId(nf).addClickHandler(app.createServerHandler("sumDoc").addCallbackElement(flexTableDoc));
Now your return function:
function sumDoc(e){
//this will return the value of the ID of the element thats clicked so in this case its test.pdf
var linkId = e.parameter.source;
}
I hope this is useful