Problem to open popup in IE
Hi,
I am facing problem to open a popup window in IE. But it works fine in Mozilla. I am getting an error as : 'document.forms[..].elements' is null or not an object' But i am passing value. and using the following code. 1st alert is working, 2nd alert is not able to open.
Code:
function openCompanyPopup( formName, idField, nameField )
{
customerPopupForm = formName;
customerPopupIdField = idField;
customerPopupNameField = nameField;
alert('formName'+formName);
alert(document.forms[formName].elements[nameField].value);
var popupURL = "ozSlsLOVCompany.jsp?searchParam="+document.forms[formName].elements[nameField].value;
var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700, height=540, scrollbars=yes');
lovWin.opener = self;
lovWin.focus();
}
thanks..
Re: Problem to open popup in IE
Instead of forms["formName"] use the formName directly or by form's index: document.myForm or document.forms[0].
With elements it would depend on what exactly you want.
For any type of element:
I'd recommend using id attribute, so you could use document.getElementById("myElementID") to access a specific element. Also if you need something more generic (say make some changes to all the elements of the same type, etc.) use document.getElementsByTagName("*") or document.getElementsByTagName("DIV") to get all the elements (or of the same type) of the page and then go through the resulting array filtering them by some property you need. Just do not use document.all for this.
For form only fields:
To get to some specific field by its name use: document.myForm.myElementName.
Or you could lits elements of a form by name: document.getElementsByName("elName"). If you need all of them do as above document.myForm.getElementsByTagName("*"). These would give a list of elements you would need to iterate through to get something specific of course.
Now regarding your method:
If you need just to pass a parameter you do not need the form, id and name at the same time. An id or a name would do it:
PHP Code:
function openCompanyPopup(idField, nameField){
var param = document.getElementById(idField).value;
//same thing as:
var param = document.getElementsByName(nameField)[0].value; //considering we need the first occurance
...
If it's imperative we use all three, then:
PHP Code:
function openCompanyPopup( formName, idField, nameField ){
customerPopupForm = document.getElementsByName(formName)[0];
customerPopupIdField = document.getElementById(idField);
customerPopupNameField = null;
//2 different forms on the same page can have 2 fields with the same name.
//Let's suppose nameField is a name of an input element, then:
formInputs = customerPopupForm.getElementsByTagName("INPUT");
for(var i=0; i<formInputs.length; i++){
if(formInputs[i].name == nameField){
customerPopupNameField = formInputs[i];
}
}
//you do not need to know the form name here since
//you already have an element object you can access to
var popupURL = "ozSlsLOVCompany.jsp?searchParam="+customerPopupNameField.value;
var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700, height=540, scrollbars=yes');
lovWin.opener = self;
lovWin.focus();
}
(don't worry, it's JS, php tags are just for code coloring)
Re: Problem to open popup in IE
hey thanks for reply.
with the following code as per your updates it is opening the popup window.
Code:
function openCompanyPopup( formName, idField, nameField )
{
customerPopupForm = document.getElementsByName(formName)[0];
customerPopupIdField = document.getElementById(idField).value;
customerPopupNameField = null;
alert(customerPopupIdField);
var formInputs = customerPopupForm.getElementsByTagName("INPUT");
for(var i=0; i<formInputs.length; i++){
if(formInputs[i].name == nameField){
customerPopupNameField = formInputs[i];
}
}
var popupURL = "ozSlsLOVCompany.jsp?searchParam="+customerPopupNameField.value;
var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700,height=540,scrollbars=yes');
lovWin.opener = self;
lovWin.focus();
}
Re: Problem to open popup in IE
It is opening the pop up window with the above code. But problem is when i open a popup window if i choose one of option by radio button and selected value should update in parent window of text box, for that i used the following method. but the popup window is not closing with the selected value. so what i need to update in the following JS method.
Code:
function acceptLOVCompany( id, cn )
{
document.forms[customerPopupForm].elements[customerPopupNameField].value = URLDecode(cn);
document.forms[customerPopupForm].elements[customerPopupIdField].value = id;
}
Re: Problem to open popup in IE
when i try it as like this it is giving an error as "document.getElementById(..)" is null or not an object. i updated like this :
Code:
function acceptLOVCompany( id, cn )
{
document.getElementsByName(customerPopupNameField).value = URLDecode(cn);
document.getElementById(customerPopupIdField).value = id;
}
Re: Problem to open popup in IE
Re: Problem to open popup in IE
What's the value for? customerPopupNameField
Sounds like your NULL
Code:
function acceptLOVCompany( id, cn )
{
document.getElementsByName(customerPopupNameField).value = URLDecode(cn);
document.getElementById(customerPopupIdField).value = id;
}
Re: Problem to open popup in IE
customerPopupNameField is the 'Name' of the selected value in popup window and which is display in parent window text filed.
Re: Problem to open popup in IE
Where the acceptLOVCompany() method is? If it's in the main page then how do you pass the customerPopupNameField parameter?
Do not forget the objects are window dependent. If you want to execute a function from one window taking a parameter from another be sure to identify the correct window.
- http://www.quirksmode.org/js/popup.html - js popup reference
- http://www.codingforums.com/archive/...p/t-32389.html - thread on passing params between windows
Re: Problem to open popup in IE
acceptLOVCompany() is calling from ozSlsLOVCompany.jsp which is popup window. From popup window i am calling that method. See the below code in popup window.
Code:
<html><head>
<script language="JavaScript">
function returnValue( id, cn )
{
opener.acceptLOVCompany(id, cn );
self.close();
}
</script></head>
<body>
<script language="JavaScript">
var id = '<%=id%>';
var cn = '<%=AhsStringUtil.jsEncode(cust.getDisplayName())%>';
returnValue(id,cn);
</script>
</body>
</html>
In the parent window i wrote the following methods.
Code:
var customerPopupForm;
var customerPopupNameField;
var customerPopupIdField;
function openCompanyPopup( formName, idField, nameField )
{
customerPopupForm = document.getElementsByName(formName)[0];
customerPopupIdField = document.getElementById(idField).value;
customerPopupNameField = null;
alert(customerPopupIdField);
var formInputs = customerPopupForm.getElementsByTagName("INPUT");
for(var i=0; i<formInputs.length; i++){
if(formInputs[i].name == nameField){
customerPopupNameField = formInputs[i];
}
}
var popupURL = "ozSlsLOVCompany.jsp?searchParam="+customerPopupNameField.value;
// var popupURL = "ozSlsLOVCompany.jsp";
var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700,height=540,scrollbars=yes');
lovWin.opener = self;
lovWin.focus();
}
function acceptLOVCompany( id, cn ) // this method calling from popup
{
//document.forms[customerPopupForm].elements[customerPopupNameField].value = URLDecode(cn);
//document.forms[customerPopupForm].elements[customerPopupIdField].value = id;
document.getElementsByName(customerPopupNameField).value = URLDecode(cn);
document.getElementById(customerPopupIdField).value = id
}
thanks..