Jump to content

smus

Members
  • Posts

    177
  • Joined

  • Last visited

Posts posted by smus

  1. How do we check if a given string is empty or not? I've tried isNull, isEmpty as well as equal and non-equal signs, the results are the same for empty and filled texts.
    My code looks like this:
     

    Call am(es)
    Call am(fs)
    
    es = ""
    fs = "ms"
    
    Sub am(s)
     if s <> "" then
      response.write "The string is not empty <br>"
     else
      response.write "The string is empty <br>"
     end if
    end Sub

     

  2. 4 minutes ago, iwato said:

    Hi, smus!

    Is your goal to detect the line breaks in str, replace each with a space, and reassign the resulting string to str?

    Also, are you certain about the nature of the linebreaks?  Do you know with certainty that they are created with /n?

    Roddy

    Hello, iwato!

    Well, basically, my goal is to make some manipulations with a string variable and it's ok with relatively small single line strings.

    But when I copy and paste a text from a .txt file and assign it to str, of course, there is an error, because JS is a line-break sensitive.

    So, I want to make multiline text become single line string programatically. For example, paste it to a textarea and then take it as a string from there.

    This code doesn't change the string:

     var e = str.indexOf("/n");
         if(e != -1){    // if we have at least one line break in str, replace /n with space
            str = str.replace(/n/g," ");
         }

     

  3. My string variable is quite big and it contains line-breaks. I need to make it single lined to be detected by JS as usual string variable:

    initial condition:

    var str = "my

    string";

    the string without line breaks:

    var str = "my string";

    How can I detect those line breaks? By replacing '/n' symbols with spaces? Are there any other ways to deal with them?

  4. I tested the code on Firefox, but it also applies styles for the rest of the HTML file:

     <div>
    <style scoped>
    h1 {color:red;}
    p {color:blue;}
    </style>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    </div>
     
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>

     

  5. 10 hours ago, Ingolme said:

    If you want to write to a file on the server then you will need a server-side program that does the writing. Javascript is not able to write to the server.

    I know, but I have asked the same question on StackOverflow. Can you please consider their solution and advise me if there is a way to somehow use it in separate files?

    Here is the link: https://stackoverflow.com/questions/50590055/angularjs-inserting-data-to-a-json-file/50596513#50596513

  6. I have 3 files: html that is displaying data from json file using AngularJS, json file containing the data, script.js that stores the scripts.

    HTML file also has a form, from which I want to add data to my json file (onsubmit="insertData()"). insertData function is going to be in script.js

    I know, I may use .push method for this, but I don't know how to apply to the json file in this case.

    script.js

    var prg = angular.module('ajsprogram', []);   
    
    prg.controller("outercont", function($scope, $http) {      //function to display json file information
            $http.get('airlines.json').success(function(data){
                $scope.info = data;
                $scope.airlineorder = 'airline';
            });
    });
    
    function newairline(an,hb,ur,cs){                         //new function to insert a data
      
    }

    airlines.json

    [
            {
               "airline" : "British Airways",
               "hub"     : "LHR",
               "url"       : "http://britishairways.com",
               "callsign":"SPEEDBIRD"     
            },
            {
               "airline" : "Air France",
               "hub"     : "CDG",
               "url"       : "http://airfrance.com",       
               "callsign":"AIRFRANS"        
             },
            {
               "airline" : "Virgin Atlantic",
               "hub"     : "LGW",
               "url"       : "http://virginatlantic.com",
              "callsign":"VIRGIN"       
            },
            {
               "airline"   : "RyanAir",
               "hub"       : "DUB",
               "url"         : "http://ryanair.com",  
               "callsign":"RYANAIR"     
            },
            {
               "airline" : "Emirates",
               "hub"     : "DXB",
               "url"       : "http://emirates.com",
               "callsign":"EMIRATES"      
            }
    ]

     

     

  7. I like w3.css, it is very useful lightweight style extension, but never knew that there were w3.js. I have no doubts, that it is also very good frameworks, however, nowadays there are so many javascript libraries, you can choose whatever you like and that fits your needs.

  8. How can I include AngularJS in JS file? Not in HTML, but in JS file. I read that it is possible to use "require" NodeJS command, to call Angular lib functions. This code generates an error ('window is not defined'):
    1. const ang = require('../lib/angular');
    2. let myApp = ang.module("myApp", []);
    3. console.log(myApp);
    4.  

    Is there a way to fully include it in a js file?

  9. Sorry for stupid question. I can't understand the purpose of cloning an array in JS. Why do we need it?

    What is the difference between:

    let a = [];
    let b = a;

    and:

    let a = [];
    let b = a.slice(0);

     

  10. If not first form is going to submit to a current tab, the solution will be more simple and elegant. We just paste this string in <head> :

     <base target="_blank">

    Voila and all our submits give a new tab with the form results!

  11. I am using this classic ASP script (VBScript) to show all the files and folders in a directory:

    The script is originally from here: https://support.microsoft.com/en-us/help/224364/creating-a-directory-browsing-page-using-asp

    <%@LANGUAGE="VBSCRIPT"%>
    <%
       Option Explicit
       On Error Resume Next
    
       ' this section is optional - it just denies anonymous access
       If Request.ServerVariables("LOGON_USER")="" Then
          Response.Status = "401 Access Denied"
       End If
    
       ' declare variables
       Dim objFSO, objFolder
       Dim objCollection, objItem
    
       Dim strPhysicalPath, strTitle, strServerName
       Dim strPath, strTemp
       Dim strName, strFile, strExt, strAttr
       Dim intSizeB, intSizeK, intAttr, dtmDate
    
       ' declare constants
       Const vbReadOnly = 1
       Const vbHidden = 2
       Const vbSystem = 4
       Const vbVolume = 8
       Const vbDirectory = 16
       Const vbArchive = 32
       Const vbAlias = 64
       Const vbCompressed = 128
    
       ' don't cache the page
       Response.AddHeader "Pragma", "No-Cache"
       Response.CacheControl = "Private"
    
       ' get the current folder URL path
       strTemp = Mid(Request.ServerVariables("URL"),2)
       strPath = ""
    
       Do While Instr(strTemp,"/")
          strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
          strTemp = Mid(strTemp,Instr(strTemp,"/")+1)      
       Loop
    
       strPath = "/" & strPath
    
       ' build the page title
       strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
       strTitle = "Contents of the " & strPath & " folder"
    
       ' create the file system objects
       strPhysicalPath = Server.MapPath(strPath)
       Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
       Set objFolder = objFSO.GetFolder(strPhysicalPath)
    %>
    <html>
    <head>
    <title><%=strServerName%> - <%=strTitle%></title>
    <meta name="GENERATOR" content="The Mighty Hand of Bob">
    <style>
    BODY  { BACKGROUND: #cccccc; COLOR: #000000;
            FONT-FAMILY: Arial; FONT-SIZE: 10pt; }
    TABLE { BACKGROUND: #000000; COLOR: #ffffff; }
    TH    { BACKGROUND: #0000ff; COLOR: #ffffff; }
    TD    { BACKGROUND: #ffffff; COLOR: #000000; }
    TT    { FONT-FAMILY: Courier; FONT-SIZE: 11pt; }
    </style>
    </head>
    <body>
    
    <h1 align="center"><%=strServerName%><br><%=strTitle%></h1>
    <h4 align="center">Please choose a file/folder to view.</h4>
    
    <div align="center"><center>
    <table width="100%" border="0" cellspacing="1" cellpadding="2">
    <tr>
       <th align="left">Name</th>
       <th align="left">Bytes</th>
       <th align="left">KB</th>
       <th align="left">Attributes</th>
       <th align="left">Ext</th>
       <th align="left">Type</th>
       <th align="left">Date</th>
       <th align="left">Time</th>
    </tr>
    
    <%
       ''''''''''''''''''''''''''''''''''''''''
       ' output the folder list
       ''''''''''''''''''''''''''''''''''''''''
    
       Set objCollection = objFolder.SubFolders
    
       For Each objItem in objCollection
          strName = objItem.Name
          strAttr = MakeAttr(objItem.Attributes)      
          dtmDate = CDate(objItem.DateLastModified)
    %>
    <tr>
       <td align="left"><b><a href="<%=strName%>"><%=strName%></a></b></td>
       <td align="right">N/A</td>
       <td align="right">N/A</td>
       <td align="left"><tt><%=strAttr%></tt></td>
       <td align="left"><b><DIR></b></td>
       <td align="left"><b>Directory</b></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbShortDate)%></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbLongTime)%></td>
    </tr>
    <% Next %>
    
    <%
       ''''''''''''''''''''''''''''''''''''''''
       ' output the file list
       ''''''''''''''''''''''''''''''''''''''''
    
       Set objCollection = objFolder.Files
    
       For Each objItem in objCollection
          strName = objItem.Name
          strFile = Server.HTMLEncode(Lcase(strName))
    
          intSizeB = objItem.Size
          intSizeK = Int((intSizeB/1024) + .5)
          If intSizeK = 0 Then intSizeK = 1
    
          strAttr = MakeAttr(objItem.Attributes)
          strName = Ucase(objItem.ShortName)
          If Instr(strName,".") Then strExt = Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
          dtmDate = CDate(objItem.DateLastModified)
    %>
    <tr>
       <td align="left"><a href="<%=strFile%>"><%=strFile%></a></td>
       <td align="right"><%=FormatNumber(intSizeB,0)%></td>
       <td align="right"><%=intSizeK%>K</td>
       <td align="left"><tt><%=strAttr%></tt></td>
       <td align="left"><%=strExt%></td>
       <td align="left"><%=objItem.Type%></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbShortDate)%></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbLongTime)%></td>
    </tr>
    <% Next %>
    
    </table>
    </center></div>
    
    </body>
    </html>
    <%
       Set objFSO = Nothing
       Set objFolder = Nothing
    
       ' this adds the IIf() function to VBScript
       Function IIf(i,j,k)
          If i Then IIf = j Else IIf = k
       End Function
    
       ' this function creates a string from the file atttributes
       Function MakeAttr(intAttr)
          MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
          MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
          MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
          MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
       End Function
    %>

    Now I need to exclude some files from viewing, for example, web.config file. I inserted this expression inside For Each loop, but it does not hide it and calls an error.

    if strName = 'web.config' Then Next
  12. This property doesn't work in latest Firefox and Chrome. The information is contradictional: w3.org, msdn.microsoft.com and developer.mozilla.org have the information on this property, although I can't find it on w3schools, it also doesn't seem to be working on TryIt Editor Sandbox. Anyone has this feature working in any browser?

×
×
  • Create New...