If condicions inside email body - javascript

I'm building an app that will send an email with variables, but i only want to include certain things if a variable is true (checkbox)
So I think i need If statments inside the email.putExtra(Intent.EXTRA_TEXT,""); but I dont seem to figure out how. it would look something like this:
public void Email (){
Date today = Calendar.getInstance().getTime();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-YYYY HH.mm");
String Time = formatter.format(today);
Intent email = new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto:"));
email.putExtra(Intent.EXTRA_SUBJECT, "Audit" );
email.putExtra(Intent.EXTRA_TEXT, Time + "\n" + "Audit Results:"
if (MainActivity2.Send_A)=true{
MainActivity2.Ok_A1 + "\n" + MainActivity2.EditText1 + "\n" + MainActivity2.POA1
}
);
I know the code is completly wrong, but is it possible to do something like this?

Build up the string, than set that string to your function call.
var extraText = Time + "\n" + "Audit Results: ";
if (MainActivity2.Send_A === true){
extraText += MainActivity2.Ok_A1 + "\n" + MainActivity2.EditText1 + "\n" + MainActivity2.POA1;
}
email.putExtra(Intent.EXTRA_TEXT, extraText);

Related

I want to re-generate part of a random generated paragraph created from arrays

I am not entirely sure what to even search to find a solution here, but essentially I have a random text generator that creates a writing prompt from a series of arrays. The behaviour I want to add to it is the ability to "reroll" any of the individual random elements by clicking on them. Here's what the current function looks like that gets returned when the button is clicked.
function art_prompt() {
return (
'<p>' + 'The main character is a ' + get_three_random_words(personality) + ' ' + get_random_word(gender) +
' who ' + get_random_word(frequency) + ' ' + get_random_word(flaws) + ' and ' + get_random_word(frequency) +
' ' + get_random_word(flaws) + '. The character is paired with ' + get_random_word(atmospheres) +
' atmosphere, set ' + get_random_word(places) + ' during ' + get_random_word(time) + '.<br><br>' +
'The scene portrays ' + get_random_word(portrayals) + '.<br><br>' + '<strong>Bonus restriction:</strong> ' +
get_random_word(bonus_restrictions) + '.' + '</p>'
);
}
So essentially, each of the get_random_word(array) functions I want to be a clickable element that generates a new random string from the same array. I have tried something where each one has a button concatenated around it and create a separate function for each array that is being brought in, but I want a more elegant solution if one exists.
Also I realize it's a bit janky of an implementation, but it's all I knew how to do when I started on it.
So I seem to have figured out a working solution. Just wrapped each object in a button, like this:
'<p>' + 'The main character is a ' + '<button onclick="rollPersonality1()" class="reroll personality1">' + personality[rand1] + '</button>, '
Using the buttons is a bit janky but it seemed to do the trick in this instance. I ran into another issue where I was trying to run the onclick function the same way I did for a static button, but it didn't work because the selector outside the function was no good. So the function for the above looks something like this.
var rollPersonality1 = () => {
var PersonalityElement = document.querySelector('.personality1');
PersonalityElement.textContent = randomPersonality();
}
I doubt this will help anybody else, but if it does that's awesome! If anyone has a more elegant way of doing this, I am not super happy with the messiness of what I came up with. So lay it on me!

how can call javascript from c# ext.net

in my project when i run it in chrome it is showing wrong time. explorer it is showing true. So i write this js code but it is still doesnt working.
This is my js;
var FormatTrxStartDate = function (value, record) {
var processDate = new Date(value);
return processDate.getDate() + "." + (processDate.getMonth() + 1) + "." +
processDate.getFullYear() + " " + processDate.getHours() + ":" +
processDate.getMinutes() + ":" + processDate.getSeconds();
};
And this is where i use it;
<ext:ModelField Name="TrxStartDate" Type="String" >
<Convert Fn='FormatTrxStartDate' />
</ext:ModelField>
Pass Parameter Value in not proper Date Format
Use processDate.getFullYear()==> processDate.getFullYear().toDateString() date data convert into String
X.Js.Call("FormatTrxStartDate ",value,record);
please try this code

Pass multiple parameters in view when using a string to call a JS function in MVC3

I am calling a function with one parameter "modalXPTO.HtmlFieldPrefix" sucessfuly like this:
modalXPTO.AdditionalJavaScriptCallback = "myFunction('" + modalXPTO.HtmlFieldPrefix + "')";
However, I would like to send more than one parameter, and I would expect this should work:
modalXPTO.AdditionalJavaScriptCallback = "myFunction('" + "{parentContainer:" + modalXPTO.ModalDivId + ", htmlFieldPrefix:" + modalXPTO.HtmlFieldPrefix + "}" + "')";
But it doesn't. Can anyone tell me what I am missing?
Here is the myFuntion declaration:
function myFunction(arg){
alert(arg.htmlFieldPrefix);
alert(arg.parentContainer);
}
I've fixed it.
modalXPTO.AdditionalJavaScriptCallback = "myFunction(" + "{parentContainer:'" + modalXPTO.ModalDivId + "', htmlFieldPrefix:'" + modalXPTO.HtmlFieldPrefix + "'}" + ")";
It is because of the misplaced "'". I wanted to pass an object with two parameters, but because of these characters I was passing a string instead.

Creating a prompt that has a time delay?

I'm trying to create a prompt that has a time delay, the value that is written in the prompt is then used in other areas of the form. I have written some javascript coding but I believe there is a minor thing that i am doing wrong as currently the prompt and delay are working, but because the setTimeout function is being used, that is what is being displayed in the form, instead of the content of the prompt. This is my Javascript?
var name = setTimeout(function(){ prompt("What is your name?", "Type your full name here")},750);
document.write("Document Written By: " + name + " (" + day + "/" + month + "/" + year + ") ")
If it depends on the value, and a function is asynchronous, you've got do it in the callback. Just like every other asynchronous piece of JavaScript...
setTimeout(function(){
name = prompt("What is your name?", "Type your full name here");
document.write("Document Written By: " + name + " (" + day + "/" + month + "/" + year + ") ");
},750);
But as #Jon commented, please do not use document.write.

Need to pass local array to a function on click

I am writing a menu system and I need to call a function when the user clicks on a specific row. I am using new function to pass the div that called the function as well as the row the user clicked on. All well and good until I try to pass a local array to the function. If I do the following:
for (i=0;i<tmpdropnumber;i++){
var dv=document.getElementById(id+i);
dv.style.cursor="pointer";
dv.onmouseover = new Function('dropover'+"('" + id + "','" + i + "')");
dv.onmouseout = new Function('dropout'+"('" + id + "','" + i + "')");
dv.onclick = new Function('dropclick'+"('" + id + "','" + i + "','"+tmparray1+"','"+tmparray2+"')");
}
As you'd expect the arrays are passed as strings. I could rebuild the arrays in the function but that seems inelegant.
if I try the following:
for (i=0;i<tmpdropnumber;i++){
var dv=document.getElementById(id+i);
dv.style.cursor="pointer";
dv.onmouseover = new Function('dropover'+"('" + id + "','" + i + "')");
dv.onmouseout = new Function('dropout'+"('" + id + "','" + i + "')");
dv.onclick = new Function('dropclick'+"('" + id + "','" + i + "',"+tmparray1+","+tmparray2+")");
}
Trying to pass the arrays it crashes. Any ideas on how I can achieve this? I am using jquery in my code so wither a javascript or jquery solution would be fine.
Do not use new Function.
You are having problems because when the string is being built, the array is being turned into a string.
basic idea to get around the toString()
for (i=0;i<tmpdropnumber;i++){
var dv=document.getElementById(id+i);
dv.style.cursor="pointer";
(function(id, i){
dv.onmouseover = function(){ dropover(id,i); };
dv.onmouseout = function(){ dropout(id,i); };
dv.onclick = function(){ dropclick(id,i, tmparray1, tmparray2); };
})(id,i);
}
But in reality there is no need to pass in an object, id.
You can always use this to get the current row and there is rowIndex on the table. Heck you can have one event handler on the table and use handlers on the table/tbody to capture the bubbling and use target/srcElement.
Instead of
dv.onclick = new Function('dropclick'+"('" + id + "','" + i + "','"+tmparray1+"','"+tmparray2+"')");
try
dv.onclick = function() {
dropclick(id, i, tmparray1, tmparray2);
};
Edit
Wrap your declaration in a anonymous function:
(function(id, i) {
dv.onclick = function() {
dropclick(id, i, tmparray1, tmparray2);
};
} (id, i));

Categories