Adding 2 Values together in JS - javascript

So this probably pretty simple to do, but I'm now just learning this. I'm trying to add two values together to fill an input
Obviously that doesn't work, can someone please lend a hand?

There is a ; between the 2 values you are adding remove it like:
var summedValues = userInfo.fname + userInfo.lname;
In javascript ; means the end of the line and therefore it is not taking the consideration the + that is after it.

Related

jQuery - replicate date from field 1 to field 2

I'm currently looking to run a simple script using jQuery and TamperMonkey as I'm doing a recurent job which is time consuming and that should be pretty basic, not sure how to achieve the below (I've recorderd a gift) - I'm new to jQuery/coding, but searching arround, using this:
//Get
var IPG = $('#txt_name').val();
//Set
$('#txt_name').val(IPG);
might be where to look at?
the script should scan the field IPG ID where -1 are present, copy the name from the channel description and copy it to IPG description
https://gyazo.com/f4bd243827df598edfdd78ec1a2d53b5
any help in achieving this would be appreciate,
many thanks,
I named HTML elements' ids by myself because I simply don't know what are those fields' id named in your app.
What you are trying to achieve it is really simple and this code can do you the trick:
var IPG = $('#IPGid').val();
if (IPG==-1)
{
var toCopy = $('#ChannelDescription').val();
$('#IPGDesc').val(toCopy);
}
Note:
This can only be done once the page is loaded it is not live for every action.
This cannot treat all lines of the table you should figure your way out of how turning it dynamic to the whole table.

how to use contains in web elements using java selenium webdriver?

I have a string which has is like ABC £12,56 and I have another box "Cashbox" which should be 15% of this value which I have to assert. Now, when I am trying to find css of both these web elements "Cashbox", I can easily find for but for ABC £12,56 I am not able to get it only for the value , its the entire string which is getting selected. Now I am thinking of using an if statement with contains. This is just a sneak peak of what I am doing, there could be many mistakes in the following code. Appreciate if someone can help me learn and tell how to do it
The way I'd do it is not check for 12,56. It'd be better to pull the value from the element text, this way it'll also work for other values.
str_value = totalPrice.getText().split("£")[1];
float_value = parseFloat(str_value.replace, ",", ".");
float_value should now be 12.56 if the text of the element truly is ABC $12,56. If you do the same with cashBox you can then compare the 2 floats

Javascript/HTML assigning a value

I am having a problem with some Javascript/HTML/CSS code. I am fairly new to creating websites, so please bear with me.
what I am ultimately trying to do is pull a dynamic value from javascript and use that to sort some divs (in a container). What I am thinking is I will assign the value to the Id and then pull those into an array to be sorted by tinysort. If there's a faster way to do this, let me know.
However, my first problem is putting the data into the id so it can be sorted. Would I do something like
document.getElementById(namesort).value = iterator;
or would I use something like myData?
Note: I don't want to display the value, I just want to use it to sort.
Please ask for clarification if needed! Thanks in advance. :)
Here is the applicable code to this problem. http://jsfiddle.net/dw77hLyp/1/
It just basically shows a very basic outline of some of my code.
Without JQuery. You can create your attribute :
document.getElementById(namesort).createAttribute('myData');
document.getElementById(namesort).setAttribute("myData","hello Im in");
Pure JS Solution:
for( i = 0 ; i < iterator.length ; i++ ) {
document.getElementsByName('namesort')[i].setAttribute('data-sort',iterator[i]);
}
That way you add each of those elements an attribute called data-sort where the iterator as a value, then could create an array insert all the namesort elements to it, use the sorting algorithm and you're done.
document.getElementById("divID").innerHTML="someContent";

Javascript syntax: inserting the value of a string into a statement

My question is simple but I can't seem to find the solution. I'm changing my html through javascript. I have a header with an image that I want to change every 3 seconds or so. I made an array with the name of the images I want in my cycle.
For changing the image I made a variable with the name of the image. I then try to insert the value of the string into the follow statement:
imageParent.style.backgroundImage = "url('images/"nextImage".jpg')";
But as you see this is completely the wrong syntax. What is the correct syntax for this?
What you're trying to do is known as string concatenation. In JavaScript it is most easily done using the + operator:
"url('images/" + nextImage + ".jpg')"
See The + Operator Used on Strings at http://www.w3schools.com/js/js_operators.asp.
try maybe +nextImage+ instead of nextImage

Adapt textarea max word plugin

How would one adapt this jquery plugin so that it counts down from how many words your allowed/you have remaining, instead of counting up to how many your allowed.
www.javascriptkit.com/script/script2/enforceform.shtml
Thanks in advance.
There is also a very simple way to do it without a maxlength attribute. (This example uses 200 as the maximum characters).
$("#YourTextareaId").keyup(function () {
var i = $("#YourTextareaId").val().length;
$('#IdOfCountdownDisplay').val(''+200-i+'');
A nice thing to remember when coding, is that a simple equation can get rid of a whole lot of complicated code.
open the maxlength.js file and put this
$field.data('$statusdiv').css('color', '').html( $field.data('maxsize') - $field.val().length )
instead of this:
$field.data('$statusdiv').css('color', '').html($field.val().length)

Categories

Resources