6

Javascript, add a string if it is true - codesd.com

 3 years ago
source link: https://www.codesd.com/item/javascript-add-a-string-if-it-is-true.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Javascript, add a string if it is true

advertisements

I need to modify this function:

function checkPermissions(fid, obj) {

$("#permissions_"+fid+"_canview").attr("checked", obj.checked);

}

if the param "n" is "true" then instead of #permissions it'll output #permissionsSet.

is that possible?


OP clarified the question to be change this whether or not a 3rd parameter was provided. Here you go.

function checkPermissions(fid, obj, n) {
  var id = n !== undefined ? '#permissionsSet' : '#permissions';
  $(id + fid + "_canview").attr("checked", obj.checked);
}

Note: This function can be freely used with passing 2 or 3 parameters (or really any number).

checkPermissions(1, this);        // Ok n === undefined
checkPermissions(1, this, true);  // Ok n === true
checkPermissions(1);              // Okish n and obj === undefined

Related Articles

Add a string to the Javascript expression

I'm not sure i'm going bonkers or something. I just can't get my head around this. I'm currently studying Python, PHP and Javascript and I'm not sure if I mix the syntaxes or anything. Anyhow, I'm going to have a function that adds a string to a phra

how to add a string at the end of the pointer to the pointer (** pointer) at C

I'm trying to add a string at the end of pointer to pointer in C, I'm using the below code the problem is I can't free what I have allocated as the pointer to pointer has values that were not all allocated memory, How can I add string at the end of a

How to add editText strings to a list

I have a MainActivity with a ListView and an add Button. When the user clicks the add Button it takes you to another activity the CreateActivity for you to enter in data or strings into the editText boxes. After that you click the create Button and i

Automatically add request string from page request to outbound page request in ASp.NET WebForms

I maintain a moderate sized public internet website for a company built using C# and ASP.Net WebForms using the .NET Framework 3.5. One of our 3rd-party marketing/lead generation consultants wants to reserve several query string codes that go into Go

how to add a string to the entire array element?

I have an array like below (0) = "apple" (1) = "orange" How can I add some string to all item in array? like apple become 'apple', orange become 'orange' Edited Private Sub test() Dim txtReader As TextReader = New StreamReader("da

How to add a string value in the php array

When i add a string value into array through array_push(), it give me a numeric value i.e $array=array("one","two","three"); $array2=array("test","test2"); foreach($array as $value){ if($value==='one'){ $p

Add a string to an autoname gnuplot

I am using the gnuplot scrip command set key autotitle columnhead to make the lables for my data. The only issue is, the column head data is numeric and so it doesnt really mean much on its own. Is there a way to add a fixed string to the autotitle,

Add a string to the contents of the file

I try to open a file and add a string to the existing content by the following code in UWP Public Async Sub AddDataToFile(sFileName As String, sStructData As String) Dim storageFolder As StorageFolder = Windows.Storage.ApplicationData.Current.LocalFo

Find a way to add a string to a tuple

y="Peter Email: [email protected] Phone: 91291212" z="Alan Email: [email protected] Phone: 98884444" w="John Email: [email protected] Phone: 93335555" add_book=str(y) ,"" + str(z) ,"" + str(w) **I am trying to add a contac

How do I add a string to the beginning of a file collection name in another directory using a shell

I have a bunch of .xml files in the folder project/reports. From the "project" folder, I need to prepend the string "TEST-" to every .xml file in the "reports" folder. I know each of the .xml files will start with the same st

Trying to Add a String Value to an SQL Database - Help and Tips

I am trying to add a string value to a SQL database in SQL Server Managemnet Studio but this does not work. What is the correct way to do this? SqlCommand addProduct = new SqlCommand("INSERT INTO dbo.Test VALUES(" + txtProductName.Text + ")

Groovy / Grails dynamically adds a String field

How to add a String type field to class (i.e to all instances of that class), like grails add an id and version fields to all domain classes? If it is possible, how to specify the type of field as String / Long etc EDIT: The added fields are not upda

Add query string (s) to the end of the url using the routes in ASP.NET MVC3

I want to add query string(s) to the end of an url using routes. How do I do this in Global.asax ? routes.MapRoute( "Detail", "{controller}/{action}/{id}/{name}", new { action = "Detail", name = UrlParameter.Optional, // it i

Can I get a list from an object, add a string to it, and deliver it to the object in a single line?

I was wondering if one can get a List from an object, add an item to it, and set the List to the object in one line. I would normally do it this way: List<String> tempList = someObject.getList(); tempList.add("some string value"); someObje

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK