SSI Web javascript not working - javascript

I am currently having a problem with SSI's Custom Java Script Verification feature. I cannot make the program give me an error when a condition is not satisfied. I checked if javascript is enabled in my browser and it was. Also, I am sure to have it enabled in the survey. My code looks something like this:
var strErrorMessage= "";
var r1value = SSI_GetValue("q1_r1_c1");
var r2value = SSI_GetValue("q1_r2_c1");
if (r2value) < (r1value)
{strErrorMessage="error";}
However, when I put a smaller number in r2, it does not give an error and it continues on to the next question.
Any help is appreciated. Thanks in advance.

I think the last part should be
if(r2value < r1value)
Right now you have mismatched parentheses.

Related

Using jQuery Validator for Empty Fields

I'm using the jQuery Validation Plugin to validate some forms, and I'm not able to quite get what I want when using with some inline table editing I'm coding. So I'm hoping someone here can shed some light.
I'm currently trying to validate for an empty or null input field. I can get it to work with the built-in rules such as "required: true" and stuff. But I can't seem to get it to validate the field if there's no data in it.
You can check out this Fiddle to see what I mean
(my last attempt was with the 'noempty' validator.addMethod)
What am I missing or overlooking?
Thanks!
Maybe try it with a function like this one to check if number of characters is less than one:
function notempty(id){
var value = $("#"+id).val();
var len = value.length;
if (len < 1){
return false;
}else{
return true;
}
}
I ended up retooling things quite a bit (other things outside my custom rules weren't working 100%), and I think I've now got it working now (I've updated my Fiddle in case it helps anyone else).

JavaScript: Change objectHTMLScriptElement

I am currently working within a CMS, cleaning up 12 websites.
Currently there are 12 identical JS files each residing within their respective site. Since they are all the same, my first initiative is to point every site to a single JS file that lives on the server.
Because I'm working within a CMS, I would have to open up 200 templates to accomplish this feat manually, so I'd, of course, rather do this dynamically.
Here is what I have done, so far:
var scripts = document.getElementsByTagName ("script");
console.log(scripts[15]);
My console.log statement returns what I'd like to replace, which is this:
<script src="/Assets/AmericanTower.com.br/uploads/content/js/main.js">
When I use alert(); rather than console.log(); I get this:
[object HTMLScriptElement]
I don't really understand why alert and console.log are showing me 2 different results.
So, I gather that I need to find a way to convert this HTMLElement to a string and then replace the string(or part of it) with the path to my new JS file.
Can anyone please shed some light?
Thank you in advance!
Robin
===============================
Thank you, L.C. Echo Chan, for your contribution. Here's how I used your suggestion and it worked like a charm!
var scripts = document.getElementsByTagName("script");
var jsPath=scripts[15].outerHTML;
var changedURL=jsPath.replace(jsPath,"RegionalGlobalAssets");
alert(changedURL);
Using outerHTML property can return the entire element
var scripts = document.getElementsByTagName("script");
alert(scripts[15].outerHTML);
Try to set you code as that
var scripts = document.getElementsByTagName("script");
console.log(scripts[15]);

Implementing Parse.Op.Increment() error

hello I'm very new to javascript. I have only been programming iOS for a year. I am stuck on trying to increment a number in cloud code. I know I need to use Parse.Op.Increment() and amount(). but I must be doing something wrong I have gotten an error since I uploaded this line.
It DID look like this.(and worked)
var sum = Record.get("totalPunches");
Sum += request.params.punches;
Record.save("totalPunches", sum);
The line I am putting on cloud code looks like this.
Parse.Op.Increment("totalPunches", amount(request.params.punches));
any help on what I am doing wrong?
thank you

Javascript, HTML, and iFrames

We have a web based type application which controls workflows for my place of business. Setting up how each user interacts with the application (Basically a web page) is a pretty straight forward process. We have the option of adding iframes into the layout.
I have written a very basic bit of javascript which sits inside an onChange function (part of the program) the script just calculates some numbers together and returns the value in a field.
What I am trying to do is get that total sum into an iframe instead of a form/element (?)
I understand this isn't very clear but is hard to go into great detail for company policy reasons.
Information is taken and calculated
for (var i = 0; i < grid.contentWindow.GetRowCount(); i++)
{
Numof = grid.contentWindow.GetSingleColumnValue(i, 'info').replace(re, "");
total = parseFloat(Numof) - total;
And is printed out into a pre created field using
CF_SetFieldValue("Printed_Field", dec_ToDecimalValue(total.toString(), 2));
Question is: how do I get the information to print in the iframe instead of "Printed_Field"?
Sorry for the lengthy and randomish post. any help would be much appreciated.
Edit: I guess at the most simplest question - How do I get the information in the forms into the inframe instead? (To be displayed in a table)
That depends on how CF_SetFieldValue is defined. By the looks of it there's a lot of very strange and probably superfluous functions that get in the way of easy-to-read-and-understand code.
Probably what you need is something like grid.contentDocument.getElementById('Printed_Field').value = dec_ToDecimalValue(total.toString(),2);

ASP.NET inline server tags

I'd like to start by saying that my code is working perfectly, this is more a "how best to do it" kind of question.
So I have code like this in my .aspx file:
function EditRelationship() {
var projects=<%= GetProjectsForEditRelationship() %>;
// fill in the projects list
$('#erProjectsSelect').empty();
for(var i in projects)
$('#erProjectsSelect').append('<option value='+projects[i][0]+'>'+projects[i][1]+'</option>');
var rels=<%= GetRelationshipsForEditRelationship() %>;
// etc
}
Again, it's working fine. The problem is that VS2008 kinda chokes on code like this, it's underlining the < character in the tags (with associated warnings), then refusing to provide code completion for the rest of the javascript. It's also refusing to format my document anymore, giving parsing errors. The last part is my worst annoyance.
I could put some of these in evals I guess, but it seems sorta dumb to add additional layers and runtime performance hits just to shut VS up, and it's not always an option (I can't remember off the top of my head where this wasn't an option but trust me I had a weird construct).
So my question is, how do you best write this (where best means fewest VS complaints)? Neither eval nor ajax calls fit this imo.
If your aim is to reduce VS complaints, and if you are running asp.net 4 (supporting Static client Ids), maybe a strategy like the following would be better?
Create a ASP:HiddenField control, set its ClientIdMode to "Static"
Assign the value of GetRelationshipsForEditRelationship() to this field on page load
In your javascript, read the value from the hidden field instead, I assume you know how to do this.
It's more work than your solution, and you will add some data to the postback (if you perform any) but it won't cause any VS complaints I guess :)
You could do this from your page in the code-behind
ClientScript.RegisterArrayDeclaration("projects", "1, 2, 3, 4");
or to construct something like JSON you could write it out
ClientScript.RegisterClientScriptBlock(GetType(), "JSONDeclarations", "your json stuff");
UPDATE Based on my comment
<script id="declaration" type="text/javascript">
var projects=<%= GetProjectsForEditRelationship() %>;
var rels=<%= GetRelationshipsForEditRelationship() %>;
</script>
<script type="text/javascript">
function EditRelationship() {
// fill in the projects list
$('#erProjectsSelect').empty();
for(var i in projects)
$('#erProjectsSelect').append('<option value='+projects[i][0]+'>'+projects[i][1]+'</option>');
}
</script>
I don't have VS2008 installed to test with, so take this with a grain of salt, but have you tried something like this?
var projects = (<%= GetProjectsForEditRelationship() %>);
Something like that might trick the JavaScript parser into ignoring the content of your expression.
For what it's worth, VS2010 correctly parses and highlights your original code snippet.
Is it an option to move this to VS2010? I just copied and pasted your code and the IDE interpreted it correctly.
The best solution is to put javascript in a separate file and avoid this entirely. For this particular function, you're doing server-side work. Why not build the list of options that you intend to add dynamically in codebehind, put them in a hidden div, and then just have jQuery add them from the already-rendered HTML?
If you have a situation where you really want to dynamically create a lot javascript this way, consider using ScriptManager in codebehind to set up the variables you'll need as scripts and register them, then your inline script won't need to escape
ScriptManager.RegisterClientScript("projects = " + GetProductsForEditRelationship());
(Basically, that is not the complete syntax, which is context dependent). Then refer to "projects" in your function.
(edit)
A little cleaner way to do this on a larger scale, set up everything you need like this in codebehind:
string script = "var servervars = {" +
"GetProductsForEditRelationship: " + GetProductsForEditRelationship() +
"GetRelationshipsForEditRelationship: " + GetRelationshipsForEditRelationship() +
"}"
and refer to everything like:
servervars.GetProductsForEditRelationship
If you do this a lot, of course, you can create a class to automate the construction of the script.

Categories

Resources