please solve my problem

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

i am getting start1.checked method is not found errorplease give me the solutionthe bold one in the program is giving the error<html><body><script type="text/vbscript">sub window_onLoad()strComputer = "172.16.0.125"Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service")document.write "<table Border=3 cellspacing=3 cellpadding=3 >"document.write "<tr>"document.write "<td> Service Name </td>"document.write "<td> Service State</td>"document.write "<td> Service Start Mode </td>"document.write "<td> Dependencies </td>"document.write "</tr>" For Each objService in colListofServices objServiceRegistryName = objService.Name objServiceDisplayName = objService.DisplayName Set colServiceList = objWMIService.ExecQuery("Associators of " _ & "{Win32_Service.Name='" & objServiceRegistryName & "'} Where " & _ "AssocClass=Win32_DependentService Role=Antecedent" ) If colServiceList.Count = 0 then d=objService.DisplayNamedocument.write "<tr>"document.write "<td>" & d & "</td>"document.write "<td width=100>"document.write "<input type=checkbox value=start1 name=start1> Start "document.write "<br/>"document.write "<input type=checkbox value=stop1 name=stop1>Stop"document.write "</td>"if objService.State = "Running" thenstart1.Checked = TrueElsestop1.Checked = Trueend ifdocument.write "<td>" & objService.startMode & "</td>"document.write "<td> NONE </td>"document.write "</tr>"Else d=objService.DisplayNameFor Each objDependentService in colServiceList x= x & objDependentService.DisplayName & vbTab Next document.write "<tr>"document.write "<td>" & d & "</td>"document.write "<td width=100>"document.write "<input type=checkbox value=start2 name=start2> Start "document.write "<br/>"document.write "<input type=checkbox value=stop2 name=stop2>Stop"document.write "</td>"if objService.State = "Running" thenstart2.checked = TrueElsestop2.checked = Trueend ifdocument.write "<td>" & objService.startMode & "</td>"document.write "<td>"document.write "<table Border=3 cellspacing=3 cellpadding=3>"document.write "<tr>"document.write "<td> DependentService Name </td>"document.write "<td> DependentService State </td>"document.write "<td> DependentService Start Mode </td>"document.write "</tr>"For Each objDependentService in colServiceList x=objDependentService.DisplayName & vbTab document.write "<tr>"document.write "<td>" & x & "</td>"document.write "<td width=100>"document.write "<input type=checkbox value=start3 name=start1> Start "document.write "<br/>"document.write "<input type=checkbox value=stop3 name=stop1>Stop"document.write"</td>"if objDependentService.State = "Running" thenstart3.checked = Trueelsestop3.checked=Trueend ifdocument.write "<td>" & objDependentService.startMode & "</td>"document.write "</tr>" Next document.write "</table>"document.write "</td>"document.write "</tr>"x=""End IfNextdocument.write "</table>"end sub</script></body></html> please give me the solution
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

There is no object called "start1" in you document.

Your approach to building the document will not work. You cannot write objects into thee document and have them be functional in the same event.

User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

hi thanks for u r replybut the below program is running...........the same logic i used in the before one<html><script language="vbscript">x=21document.write "<input type=checkbox name=one>one"document.write "<input type=checkbox name=two>two"if x=20 thenone.checked=Trueelse two.checked=Trueend if</script></html>
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

This is one way that works better but not the best way.


s = s & "<table Border=3 cellspacing=3 cellpadding=3 >"s = s & "<tr>"s = s &"<td> Service Name </td>"s = s &"<td> Service State</td>"s = s &"<td> Service Start Mode </td>"s = s &"<td> Dependencies </td>"s = s &"</tr>"

document.body.innerHTML = s

For more complete instructions see:

http://www.w3schools.com/htmldom/default.asp
http://www.w3schools.com/htmldom/dom_obj_table.asp
Here is an example of hot to add rows to a table:

http://www.w3schools.com/js/tryit.asp?f ... _insertrow

Here is my examle of how to manage the DOM by loading it from a CSV file.

http://www.scriptinganswers.com/forum2/ ... 0&KW=table



jvierra2009-08-14 00:05:35
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

Great example Ras.

Here is an example using the posters design.

This shows how a table is generated using DHTML and the DOM. Notice that the code is smaller and easier to manage. The code also execute many times faster than using the document writer.

Save the following as an HTA.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
<html>  
<head>  
    <META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1">  
    <script type="text/vbscript">  
      
        sub window_onLoad()  
          
            strComputer = "."  
            Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")  
            Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service")  
          
            For Each objService in colListOfServices  
                set r = tbl1.insertRow(-1)  
                set c = r.insertCell(-1)  
                c.innerHTML = objService.DisplayName  
                set c = r.insertCell(-1)  
                c.innerHTML = objService.State  
                set c = r.insertCell(-1)  
                c.innerHTML = objService.StartMode  
                  
                ' this gets changed to an insert table.  
                set c = r.insertCell(-1)  
                c.innerHTML = "&nbsp;"              
            Next  
          
        end sub  
      
    </script>  
</head>  
<style type="text/css">  
        #tbl1 td{  
            overflow: hidden;   
            border-collapse: collapse;   
            empty-cells: show;  
            font-family: Arial;   
            font-size:8pt;   
            font:menu;   
            padding:0pt;  
            margin: 0;   
            border: 1px;  
            border-style: solid;  
            border-color: black;  
        }  
</style>  
<body>  
<div>  
<table id="tbl1">  
    <caption><h2>Services Status<h2></h2></caption>  
    <thead>  
        <tr>  
            <td>Name</td>  
            <td>State</td>  
            <td>StartMode</td>  
            <td>Dependencies</td>  
        </tr>  
    </thead>  
    <tbody>  
    </tbody>  
</table>  
</div>  
</body>  
</html> 

The processing has been allocated to the DOM as much as possible. All positioning and format have been defered to CSS as this is faster, more flexible and easier. The table can be inserted or just used by "ID".

Note that the "name" attribute is not used as this has been deprecated by W3C and does not work in VBScript for direct reference. Only the ID works.

A document declaration has been used to prevent the CSS styles from rendering differently in different environments. The version of IE installed can effect this so it is recommended.

Note for RAS - "getElementByID" is not needed in vbscript as the ID can be used directly. Note I jsut refere to teh table as "tbl1" without getting the object. Either method works but vbs allows this shortcut where Java doesn't.

I like yuo synthetic way of clearing the HTML by reloading the document. This is good since FORMS don't work in an HTA.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

The name property never resolves to an object. You need to getElementByName to retrieve it by name. As I pointed out, "name" was discontinued years ago and only kept around for backwards compatibility. HTML can use name. DHTML cannot.

This: "td_" & intRow.InnerHTML = "Complete Successfully" could never work in any environment. An object can only be declared at "compile" time or before parsing. YOu can build a string and use it to retrieve an object but you cannot use a string as a reference to an object. THis is true of nearly all programming environments although PowerShell has a unique way to get around this.

In any case your code above is fine. My issue with the "name" attribute is for other users to try and get them to avoid fgetting in the habit of using name="xxx" in favor of id="xxx".

Other rules to keep in mind:

1. All attributres and tags are lower case.
2. All attribute values must be enclosed in either single or double quotes.
value="123" OR value='123'
NOT
value=123 OR value=something

3. tags need to be corerctly closed:
<br> should be <br />
4. <input.... does not get closure.
<input type="button" value"MyButton">
NOT
<input type="button" value"MyButton"/>

These few things will help to avoid a lot of traps.
User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

hi jvierra, Thanks for u suggetions but i cant understatd the code which u have giveni am new to vbscript and i dont know DOM. So please add my requirements to the program u have given. My requirement is as i mentioned above i should have two radiobuttons at every state option like (radiobutton) Start(radiobutton) stopif i click start radiobutton the service has to startif i click stop radio button the service has to be stop so please please add this to the prog u have given.........dileep2009-08-18 20:50:12
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

please solve my problem

Post by rasimmer »

Dileep,

Firstly, you should remove your email address from the post above.....don't feed the spammers

Second, this is not a script writing service, it's a place to get your questions answered. You should atleast attempt to write the code and post if you have questions, not expect a member to write it for you.

Seeing as how I'm a nice guy, I didn't look at the existing code jvierra provided, but this is basically how you would do what your asking...

VBScript:

Code: Select all

Sub Manage_Service(service_name, state)
    Set objWMI = GetObject("winmgmts:!.rootcimv2")
    strQuery = "Win32_Service=" & "'" & service_name & "'"
    Set objService = objWMI.Get(strQuery)
    Select Case LCase(state) 
        Case "start"
            errReturn = objService.StartService()
        Case "stop"
            errReturn = objService.StopService()
        Case Else
            spn_Status.InnerHTML = "Service state not defined"
    End Select
    If errReturn = 0 Then
        spn_Status.InnerHTML = "The service was " & state & "ed successfully!!"
    Else
        spn_Status.InnerHTML = "ERROR: Service returned the following error - " & errReturn
    End if
End Sub

HTML:

Code: Select all

<fieldset>
        <legend>Messenger Service:</legend> 
         <input type="radio" name="rad_MsgService" value="Start" onClick="Manage_Service 'messenger', me.Value">&nbsp Start
         <input type="radio" name="rad_MsgService" value="Stop" onClick="Manage_Service 'messenger', me.Value">&nbsp Stop
    </fieldset>
    <span id="spn_Status"></span>
rasimmer2009-08-18 08:24:59
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

Ras-

Well. The user is asking for checkboxs I think.
The code you posted can't be used with the DOM model that I posted. We need to use createElement dynamically.

Your vbscript is good and just needs to be converted to a call and assigned to the "onclick" event of the checkbox object.

And yes...I am trying not to write scripts on demand except when it will server as a decent model of how to best approach a problem. Like you I have always felt that ScriptingAnswers is a place for scripters to come to learn and/or have specific questions answered by scripters with more or different experience. Collaboration.

Thanks


I posted teh links to teh w3schools web site which is a good tutorial on how to manage the DOM.

User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

please solve my problem

Post by rasimmer »

@jvierra,

Cool example using the data island. Question, is there a preferred method to populate that? Say I want my queries to be faster and app load time to take a little longer. So, I want to put a message up and say "Please wait while the app gathers information...." and populate the XML data island with the data.
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked