Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form name in a function 3

Status
Not open for further replies.

A1Pat

IS-IT--Management
Jun 7, 2004
454
0
0
US
Hi all,
I'm trying to modify this original function that is used to open a form when called:
Code:
function Do_Connect()
{	
	mySDK.WESPSDKMonitor.ClientPullingMode = 0;
	mySDK.WESPSDKMonitor.Connect();
}
and as you can see, the form name "mySDK" is located right in the beginning of the 2 lines.

What I want to do is to open more than one form instead by doing this:
Code:
function Do_Connect()
{	
	var arrCams = Channel.value.split(",");
	var x;
	for (x=0;x<arrCams.length;x++) {
          mySDK[arrCams[x]].WESPSDKMonitor.ClientPullingMode = 0;
		mySDK[arrCams[x]].WESPSDKMonitor.Connect();
	}
}
however, an error is given "mySDK is undefined" as the function goes.

I tried to hard-code by replacing the For loop with this given form name as mySDK1, mySDK2:
Code:
function Do_Connect()
{	
	var arrCams = Channel.value.split(",");
	var x;
	for (x=0;x<arrCams.length;x++) {
		mySDK1.WESPSDKMonitor.ClientPullingMode = 0;
		mySDK1.WESPSDKMonitor.Connect();
		mySDK2.WESPSDKMonitor.ClientPullingMode = 0;
		mySDK2.WESPSDKMonitor.Connect();
	}
}
and it works!

So, my question is... what's wrong here? why mySDK(x) doesn't work while mySDK1 is ok?

Please help!
 
Because mySDK[1] is not mySDK1 but "mySDK1", it is, it's just a String, not the object you want to invoke.

Cheers,
Dian
 
You should be able to use the syntax I gave in my earlier response to you here:

thread216-1370970

(the line where I assigned the "frm" variable).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
A way to do this, but I don't like it is to use the eval() function.

Code:
function Do_Connect()
{    
    var arrCams = Channel.value.split(",");
    var x;
    for (x=0;x<arrCams.length;x++) {
        eval("mySDK" + arrCams[x] + ".WESPSDKMonitor.ClientPullingMode = 0");
        eval("mySDK" + arrCams[x] + ".WESPSDKMonitor.Connect()");
    }
}

This is assuming the array arrCams contains values 1 and 2.

[monkey][snake] <.
 
Yeah, I was aware of that, but I posted such that there was minimal change in the original written code.

[cheers]

[monkey][snake] <.
 
I'm curious now as to what sort of form element "WESPSDKMonitor" is that has extra properties & methods... but this should work:

Code:
function Do_Connect() {    
    var arrCams = Channel.value.split(',');
    for (var x=0; x<arrCams.length; x++) {
    	var frm = document.forms['mySDK' + x].elements;
		frm['WESPSDKMonitor'].ClientPullingMode = 0;
		frm['WESPSDKMonitor'].Connect();
    }
}

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you all for your replies...

To Dan,
I'm sorry that I still 'till now haven't had a chance to test your code just yet, however, be asure that I will try it eventually as soon as possible cause I do want to learn a better and proper way for coding.

To Monksnake,
I tested your code because, obviuosly, it is easiest and quickest way for me to do right now. I understand you and Dan have a reason not wanting to utilize this eval(), and I'll take that in mind as well. And you know what, IT WORKS!!!

To Dian,
Thank you for explaination and I now understand in order to have it as a string, eval() is one of the way to do so.

Thank you all again!
 
Good job monksnake, way to reinforce bad habits [thumbsup2]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Dan,

I just quickly tried your code given on the above and I got an error:
'document.forms[...].element' is null or not an object

As I understand, the WESPSDKMonitor is the camera ID name that was given inside the Object in each form.

I tried:
Code:
function Do_Connect() {    
    var arrCams = Channel.value.split(',');
    for (var x=0; x<arrCams.length; x++) {
        var frm = document.forms['mySDK' + x].elements;
        frm.WESPSDKMonitor.ClientPullingMode = 0;
        frm.WESPSDKMonitor.Connect();
    }
}
and the same error is still there, I guess the problem is at this line: var frm = document.forms['mySDK' + x].elements;
 
Well - this is why I asked in my previous post what sort of form element WESPSDKMonitor was.

I asked because alarm bells were ringing, due to no form element type I know having extra methods or properties, and because the syntax I'm giving assumes you are using normal form elements.

If WESPSDKMonitor isn't a form element, then it will not work. But if it's not, you also have to wonder why you have it in a form at all?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
You are right, Dan.

The whole coding in the page is not normal to me when I first look at it at all.

I can show you the actual original form:
Code:
<FORM name=mySDK>
							<OBJECT id=WESPSDKMonitor 
							codeBase=./WESPSDK.cab#version=1,2,2,8 height=243 width=360 
							data=data:application/x-oleobject;base64,oEeRsf3CH0u9IDo+GrxPwwADAAA1JQAAHRkAAA== 
							classid=clsid:B19147A0-C2FD-4B1F-BD20-3A3E1ABC4FC3><param name="Stretch" value=0></OBJECT>
						</FORM>

And from here, I used ASP code to do FOR loop that Split the array of channel I saved in a string ie:1,2,3 to this form:
Code:
arrChannels = Split(Session("cam_no"), ",")
					x = 0
					response.write "<table cellpadding='5' width='800' align='center'><tr>"
					For Each strOneWord in arrChannels
						if x = 4 then
							x = 0
							response.write "</tr><tr>"
						end if
%>
						<td width="180" valign="top" align="center"><FORM name="mySDK<%=strOneWord%>">
							<OBJECT id=WESPSDKMonitor 
							codeBase=./WESPSDK.cab#version=1,2,2,8 height=121 width=180 
							data=data:application/x-oleobject;base64,oEeRsf3CH0u9IDo+GrxPwwADAAA1JQAAHRkAAA== 
							classid=clsid:B19147A0-C2FD-4B1F-BD20-3A3E1ABC4FC3><param name="Stretch" value=0></OBJECT>
							<BR><input type="button" value="Cam <%=strOneWord%>" onClick="Do_PlayVideo(<%=strOneWord%>)">
						</FORM></td>
<% 	
						x = x + 1
					Next

And the strOneWord is the Cam# and also the Form# that I used for the js code function.
The unsual thing about this form is whoever created it had put form's elements such as <option select> or <input> outside the <form> itself.

I hope those info might give a better view.
 
And do not forget, the form's elements that I mentioned have included <... onclick...> to activate Do_Connect function. Just to have you know. :)
 
In the loop you have, each of your objects will have the same ID - which is not valid. The ID needs to be unique.. .so try appending the loop number to the end.

That way, you can simply refer to each control via:

Code:
document.getElementById('WESPSDKMonitor' + n)

where n is a number correspoding to the camera you want.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I had thought of that, but instead of having different # for WESPSDKMonitor, I did the form's names. Don't you think that serves the same purpose?
 
since this is a new development about the object, I did redo the form so that the objects will be # and the form name is only one.
Code:
<TD align="center" valign="top"><FORM name="mySDK">
<%	
					arrChannels = Split(Session("cam_no"), ",")
					x = 0
					response.write "<table cellpadding='5' width='800' align='center'><tr>"
					For Each strOneWord in arrChannels
						if x = 4 then
							x = 0
							response.write "</tr><tr>"
						end if
%>
						<td width="180" valign="top" align="center">
							<OBJECT id=WESPSDKMonitor<%=strOneWord%> 
							codeBase=./WESPSDK.cab#version=1,2,2,8 height=121 width=180 
							data=data:application/x-oleobject;base64,oEeRsf3CH0u9IDo+GrxPwwADAAA1JQAAHRkAAA== 
							classid=clsid:B19147A0-C2FD-4B1F-BD20-3A3E1ABC4FC3><param name="Stretch" value=0></OBJECT>
							<BR><input type="button" value="Cam <%=strOneWord%>" onClick="Do_PlayVideo(<%=strOneWord%>)">
						</td>
<% 	
						x = x + 1
					Next
					response.write "</tr></table>"
%>						
					</FORM></TD>
would you please rephrase your code for my better understanding.
Code:
function Do_Connect() {    
    m_ipAddr	= IPAddr.value;
	m_portNum	= PortNum.value;
	m_userID	= UserID.value;
	m_password	= Password.value;
	
	var arrCams = Channel.value.split(',');
    for (var x=0; x<arrCams.length; x++) {
        var frm = document.forms['mySDK' + x].elements;
        frm.WESPSDKMonitor.ClientPullingMode = 0;
        frm.WESPSDKMonitor.Connect(m_ipAddr, m_portNum, m_userID, m_password);
    }
}
 
If you change this:

Code:
var frm = document.forms['mySDK' + x].elements;

to this:

Code:
var cam = document.getElementById('WESPSDKMonitor' + x);

then instead of referring to "frm." you should be able to refer to "cam." for the same functionality.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,
I tried like you suggested, but I got an error: Object Required.

This really compels me to utilize the Eval() tool that you guys seemed to dislike so much. Would you please tell me the pros and cons why people should or should not use the eval(). I googled around but couldn't find a site explain the pros/cons about such utility.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top