Different names - JS and CS - javascript

Im Trying to get to the same text on JS and on CS
JS CODE:
var LblSits = document.getElementById('<%=SelectedSits.ClientID%>');
LblSits.textContent+= NumId;
CS Code:
int Sits = int.Parse(SelectedSits.Text);
When i Run This , i can see the SelectedSits Label updating with numbers
but when im trying to Debug it from the CS its always empty ("").
the diffrence of the names driving me crazy.
same happened to me With ImageUrl on CS and src on JS until i figured it out.
Which name connected to whom?
What can i do?
Why is that always empty?

From the C# code, you can only see content that is changed in JavaScript code for specific controls that support sending the changes made by JavaScript on the client back to the server.
Instead of using a Label, use a TextBox or HiddenField control.

Related

How to store variable and set the variable in field

I'm using Selenium 3.17.0.
I want to type a text from a javascript, but it doesn't work!
I have tried this (this types the text "undefined")
and this (this types the entire script as text)
but nothing works! maybe I'm doing wrong the javascript but I don't know, I'm new in all of this, please help!
btw this is my first post, sorry if I'm doing it wrong.
If I understand your question correctly, you are trying to generate a random string using javascript and then store the value in a variable. Then enter that variable value using type.
you have to use execute script command to run the javascript and target (your javascript) should be return "free text" + Math.floor(Math.random()*100) as shown in the below screenshot.

Converting Java code to JS (jsweet error)

I wrote a code in Java which gets number of each piece type and fills some area with tetris block and print filled array.
I wanted to make website (probably on github.io, no server) which calculates this and print for other users.
I wrote the code in Eclipse(jdk 12.0.2) and no error on it.
But when I convert code with JSweet, it gave me some errors:
1.
final EnumMap<P,Integer> M = new EnumMap<>(P.class);
->type 'P' does not satisfy the constraint 'Enum<P>'
2.
EnumMap<P,Integer> M = (something);
Iterator<Piece> P = new ArrayList<>(M.keySet().iterator());
->property 'slice' does not exist on type 'Set<P>'
Then I found GWT, but it seems like wont work without server... I tried it but it failed.
How to fix errors on JSweet? Or is there other apps to convert Java code to js?
(This is my first project in Java and Eclipse, and newbie in js)

How to use javascript split in Qualtrics

Very new to Javascript and have been searching the webs for assistance, but haven't quite found a solution.
I am attempting to use javascript to split/remove the output of a particular field. The data in the survey is being pulled from our school's database after a user logs in to the survey via shibboleth. All the information is being displayed, so that part works, but one particular field is appending an email address (#email.com) to a field.
I want to omit this part from being displayed. Either my javascript is incorrect or the javascript is not being loaded/read. The javascript code was borrowed from a colleague and it works on his surveys, but he has a lot of other things going on in his survey and this works for him.
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var iid = "${e://Field/theUTIID}";
var split_array = iid.split("#",1);
var eid = split_array[0];
Qualtrics.SurveyEngine.setEmbeddedData('theUTIID', eid);
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var iid = "${e://Field/theUTIID}";
var split_array = iid.split("#",1);
var eid = split_array[0];
Qualtrics.SurveyEngine.setEmbeddedData('theUTIID', eid);
});
I have this in both the Onload and OnReady for testing. Doesn't matter if I have this is one location or the other, I am not getting the desired results.
I only have one question on the survey (it's just a test survey) and so the javascript code is with the first and only question.
Survey Question has the following in a text entry. Again, output is displayed, but need the #email.com to removed from the EID field.
The code looks correct (other than it only needs to be in one or the other function). I'm guessing it isn't a problem with the code, but where you are trying to pipe the embedded variable. The JavaScript above has to be attached to a question on a separate page before the place where you want to pipe it.
Add a page break, then pipe theUTIID into a question on the next page.

sharepoint Online/365 Jquery, Set Lookup Column Not working e.i ($("select[Title='Column']")

I've been doing some work on Sharepoint Online/365 and have got stuck trying to set the value of a lookup or choice column in NewForm.aspx
Narrowed my problem down to not being able to set lookup/Choice Columns
I have simplified a code on my page down to
//Phase being a Choice Column & Closure a case sensitive valid option
$("select[title='Phase']").val("Closure");
//ProjectName being a Lookup Column & Test2 a case sensitive valid entry in the list
$("select[title='ProjectName']").val("Test2");
I have no problem setting text fields as the following code works fine on a text field I created
$("input[title='TextField']").val("Test2");
I have used the following Jquery libraries 1.7.2/min.js and 1.11.3
Not sure whether you used _spBodyOnLoadFunctionNames.push() method for your logics. Usually you have to wait all SharePoint DOM objects are loaded and then to execute your jQuery code. If you used SharePoint JavaScript library, you probably needs to call ExecuteOrDelayUntilScriptLoaded() to make sure your call is called after curtain SharePoint .js files are loaded.
First Thanks "Verona Chen" and " DIEGO CARRASCAL" because of who i've learnt a few other tricks in SharePoint which will help with other projects.
My original script before the question was trying to use a query string to populate a field in newform.aspx (which i have done on sharepoint 2013 with code i have found here on)
Unforuntaly with sharepoint online/365 This code was no longer working.
This code has fixed my issue (though it does change how a few previous pages are constructed)
Appologies if this doesn't directly answer the above question (as this was me trying to breakdown the overall issue i was having into something simpler and easier to address based on me narrowing down the issue in my original code) however as I am now up and running, it seems only polite to post the outcome.
Prior to code, i have a projects list with a "ProjectName" field. I was sending the field name into a URL and querystring to get mylist/newform.aspx?ProjectName=Test2
I was then trying to pull that Test2 into the lookup field (liked to the project list) "ProjectName" in the list "MyList"
But even when loading the function for my old script with _spBodyOnLoadFunctionNames.push() it wasn't working.
After playing with this for a while and after some looking around i found this peice of code
<script type="text/javascript">
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
'ProjectName': {
'NewForm': renderTaskCategory
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function renderTaskCategory(ctx) {
//extract cat parameter from a query string
var GetProjID = GetUrlKeyValue('ProjID');
//set lookup field value
ctx.CurrentFieldValue = GetProjID;
//default template for rendering Lookup field control
return SPFieldLookup_Edit(ctx);
}
</script>
This means that i have to change my previous url builds to create mylist/newform.aspx?ProjID=2
This script then finds item ID 2 (which happens to be test2 in this case) and puts the title of item 2 in my lookup field ProjectName
Thanks again to those that helped earlier.
And apologies again if this doesn't directly answer the question i originally asked.

Can I get result from javascript and use it in vb.net?

I have this code to show confirm message using vb.net, but I want to get the return result and use it in vb.net code.
Dim str As String = "<script>" &
"$('.test').live('click',function(){" &
"confirm('test');" &
"})</script>"
ScriptManager.RegisterClientScriptBlock(control, GetType(Button), "sas", str, False)
I am thinking in storing the result data in html compnent and use it in vb.net code, is there another solution ?
You can store the result in a hidden field (<input type="hidden">), then retrieve it in your code after postback.
Not directly. The server side code is outputting text down a one-way channel. The JavaScript is running on a different system. You can't get data from the JS to the server without making a new HTTP request.
See also Using Pylons global variables with JavaScript which is the same problem, just with a different language.

Categories

Resources