Get data from script tag - javascript

How can i get the email address from this script
<script>
var wcRQlKjfP = 'sales#websaucestudio##.com';
var wcRQlKjfP = wcRQlKjfP.split('#');
document.getElementById('wcRQlKjfP').innerHTML = wcRQlKjfP[0]+wcRQlKjfP[2]+wcRQlKjfP[1]; document.getElementById('wcRQlKjfP').href = 'mailto:'+wcRQlKjfP[0]+wcRQlKjfP[2]+wcRQlKjfP[1];
</script>
Help me!
Thanks a lot!

Although your variable has a strange name, all you need to do is combine the three parts (wcRQlKjfP[0] + wcRQlKjfP[2]).
wcRQlKjfP[1] can be completely ignored, as it evaluates to an empty string.
Here I'm logging the result to the console, but you could always assign to a new variable and then reference that variable.
var wcRQlKjfP = 'sales#websaucestudio##.com';
var wcRQlKjfP = wcRQlKjfP.split('#');
document.getElementById('wcRQlKjfP').innerHTML = wcRQlKjfP[0] + wcRQlKjfP[2] + wcRQlKjfP[1];
document.getElementById('wcRQlKjfP').href = 'mailto:' + wcRQlKjfP[0] + wcRQlKjfP[2] + wcRQlKjfP[1];
console.log(wcRQlKjfP[0] + wcRQlKjfP[2]);
<a id="wcRQlKjfP"></a>
Hope this helps! :)

Related

Compare values of object JavaScript

I have an object in JS like this:
var getToDoValue = document.getElementById("toDoInput").value;
var nameOfTeamMember = "Tobias";
var person = new Object();
person.task = "Task: " + getToDoValue;
person.member = "Member: " + nameOfTeamMember;
But problem comes when I try to enter the value of "nameOfTeamMember into an if statement:
var mem = person.member;
if (mem == "Tobias") {
console.log("works");
}
This does not work. But when I just console.log "var mem" outside of if statement it gives me "Member: Tobias". Any suggestions? Im still kinda new to JS so prob something with the comparisons
the issue with you code is that the value in person.member is "Member: Tobias" as you pointed out from the result of your console.log, which is the result from the line of code below where you are concatenating the name with the string "Memeber: " and assigning it to the member property.
person.member = "Member: " + nameOfTeamMember;
One option you could use to do the comparison would be:
if (mem.contains("Tobias", 8) {
console.log("works");
}
The 8 is so your search starts after the colon (:) so you don't include "Member:" in it, just what comes after it, which is the actual member name.

Convert comma's into periods js

So I'm trying to make a calculation but it obviously wont calculate with ',' in the numbers. I want to change these vars and make the ',' into '.' using javascript
oldSum.value = '48,35'
newSum.innerHTML = '€43,40'
var oldSumPre = oldSum.value;
var oldStripped = oldSumPre.replace(/,/g, ".");
var newSumPre = newSum.innerHTML;
var newStripped = newSumPre.replace(/,/g, ".");
bedrag.innerHTML = oldStripped - newStripped;
Is what Im doing right now.. but it changes bedrag.innerHTML into NaN
var str = "R,e,p,l,a,c,e";
var res = str.replace(/,/g, ".");
alert (res);
Suppose your variable is vNum. You need to replace all commas with '.' using this
vNum = vNum.replace(",", ".");
In general you could use a localization / internationalization library, which will solve some other tasks you are likely to run into as well.
For example this one:
https://github.com/jquery/globalize/blob/master/doc/api/number/parse-number.md
Snippet:
Globalize.locale( "es" );
Globalize.parseDate( "3,14" ); // 3.14

Unable to clear the Input Fields

I have a very basic code. However I am not able to clear the of the Year with the id (userYOB) on clicking the alert ok. The code works only for the which asks for year. Its not just the clearing of but I also want to bring the place holder back once alert is clicked ok.
Thanks for help.
[fiddle] http://jsfiddle.net/vineetgnair/j8zjjj9r/26/
var d = new Date();
var currentYear = d.getFullYear();
function test() {
var userYearOfBirth = document.getElementById("userYOB").value;
var authorisedAge = 19;
var currentAge = parseInt(currentYear - userYearOfBirth);
//console.log(currentAge);
if (currentAge < authorisedAge) {
alert("You are not authorised to visit the site");
document.getElementById("userYOB").value = " ";
} else {
alert("Welcome to the site!");
userYearOfBirth = " ";
}
}
In else part say
document.getElementById("userYOB").value= " ";
instead of
userYearOfBirth = " ";
Because userYearOfBirth is a simple string so updating it doesn't update the value of textbox.
Please add the following lines after the else part,
document.getElementById("userYOB").value= " ";
document.getElementById("userMOB").value= " ";
document.getElementById("userDOB").value= " ";
This will clear the fields and bring back the placeholder. The reason why
userYearOfBirth = " "
doesn't work is because in the following line the variable actually holds the value not the element itself,
var userYearOfBirth = document.getElementById("userYOB").value;
It would be more advisable if you, replaced the above line with,
var userYearOfBirth = document.getElementById("userYOB");
now you have the reference to the element in the variable. You can easily change the elements value by,
userYearOfBirth.value = " ";
Personally, I prefer the latter method cause its less code. I hope this helps!! :)

access javascript variable into the .ashx page

I have a JavaScript, which returns 2 variables. I just want to access those variables in the generic handler(ashx) page but I can't. Can anybody give some suggestion?
var myArray = [txt, value];
var url = "insertComments.ashx?dat=" + myArray.join();
Change your Javascript :
var url = "insertComments.ashx?datTxt=" + txt + "&" + "datValue=" + value;
and in handler access that values with :
string txt = context.Request.Params["datTxt"];
string val = context.Request.Params["datValue"];

Javascript eval

I am trying to get the following working. It seemed to work initially, but somehow it stopped working
var setCommonAttr = "1_row1_common";
var val = document.getElementById("abc_" + eval("setCommonAttr")).value;
what is wrong with above?
The above code is little different from what I am trying to accomplish. I gave the above example just not to make things complicated here. Below is what I am trying to accomplish:
First I am getting an existing element as follows. The element is a
<tr id="row_1_4_2009_abc" class="rowclick">
<td></td>
</tr>
I am using jquery to get the id on click of a row:
$(".rowclick").click(function() {
var row_id = $(this).attr("id");
var getAttributes = row_id.split("_");
var setCommonAttr = getAttributes[1] + "_" + getAttributes[2] + "_" + getAttributes[3] + "_" + getAttributes[4];
var new_row_id = document.getElementById("new_row_" + setCommonAttr).value;
});
You shouldn't need eval() to do this. The value you want is already a variable in JavaScript. Try:
var setCommonAttr = "1_row1_common";
var val = document.getElementById("abc_" + setCommonAttr).value;
Will everything be in that form? row_xxx_xxx_xxx_xxx
if so, why not var new_row_id = document.getElementById("new_" + row_id).value;
You don't need to call eval().
You can just concatenate the string with the variable:
var setCommonAttr = "1_row1_common"; var val = document.getElementById("abc_" + setCommonAttr).value;

Categories

Resources