[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Need to loop through a form collection, and then execute a window open function

Hi,

I am a bit of a novice with Javascript, and I am having problems getting this code to do anything at all.

This is my Javascript code:

<script language="JavaScript">
<!-- Begin
function printProps() {
// grab all PRINTs in the document
  pIDs = document.getElementsByTagName("PRINT");
 
// loop through PRINT collection
  for (var d=0; d < pIDs.length; d++) {
          if (pIDs.checked == true) {
                myPID = pIDs[d].value;
          newWindow = window.open("PropertyViewAuto.asp?PID=" + myPID,"audio","scrollbars=1,width=750,height=600,top=100,left=200");
              newWindow.focus();
        }
  }
}
//  End -->
</script>

And the form looks like this:

<form name='batchprint' action='BatchPropertyHandling2.asp?P=1' method='post'>
<table>
<tr><td><input type='checkbox' name='PRINT' value='123'> My property address</td></tr>
<tr><td><input type='checkbox' name='PRINT' value='456'> My property address</td></tr>
<tr><td><input type='checkbox' name='PRINT' value='789'> My property address</td></tr>
</table>
<input type="submit" onClick="if (printProps()) document.batchprint.submit(); return false;">

What I want to do is have the user check the box of certain properties, and when they click submit, a new window will open with the details of the selected properties - one window for each selected property.

I would be most obliged if you could help!  At the moment, the javascript code does not appear to be executed at all.
0
hmaloney
Asked:
hmaloney
2 Solutions
 
thirdCommented:
try this,

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Author: Third Santor</title>
<script>
<!-- Begin
function printProps(obj) {
  var myPID;
  var flag = false;
// grab all PRINTs in the document
  pIDs = obj.PRINT;
 
// loop through PRINT collection
  for (var d=0; d < pIDs.length; d++) {
         if (pIDs[d].checked == true) {
              myPID = pIDs[d].value;
                    alert(myPID);
         newWindow = window.open("PropertyViewAuto.asp?PID=" + myPID,"audio","scrollbars=1,width=750,height=600,top=100,left=200");
            newWindow.focus();
             flag = true;
       }
  }
  return flag;
}
//  End -->
</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form name='batchprint' action='BatchPropertyHandling2.asp?P=1' method='post' onsubmit="return printProps(this);">
<table>
<tr><td><input type='checkbox' name='PRINT' value='123'> My property address</td></tr>
<tr><td><input type='checkbox' name='PRINT' value='456'> My property address</td></tr>
<tr><td><input type='checkbox' name='PRINT' value='789'> My property address</td></tr>
</table>
<input type="submit">
</form>
</body>
</html>
0
 
hmaloneyAuthor Commented:
Thanks third!

That nearly worked.  The javascript is certainly now executing, but if I select all 3, after opening each window, only one window remains at the end of its execution - the window for the last item.  Do you know how to make sure that all the windows stay open?

Thanks heaps!
0
 
ZvonkoSystems architectCommented:
Add this to third's code:

newWindow = window.open("PropertyViewAuto.asp?PID=" + myPID,"audio"+d,"scrollbars=1,width=750,height=600,top="+(100+(d*20))+",left="+(200+(d*20)));


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
choo_chuCommented:
Hi hmaloney,

I noticed that the action attribute of your form is: 'BatchPropertyHandling2.asp?P=1'.  In some browsers the value (i.e. P=1) may not be passed in the Request.Form collection.  If you pass it in a hidden form field, the value for sure will be passed in the Request.Form collection.  Your form would then look like this:

<form name='batchprint' action='BatchPropertyHandling2.asp' method='post' onsubmit="return printProps(this);">
<table>
<input type="hidden" name="P" value="1"/>
<tr><td><input type='checkbox' name='PRINT' value='123'> My property address</td></tr>
<tr><td><input type='checkbox' name='PRINT' value='456'> My property address</td></tr>
<tr><td><input type='checkbox' name='PRINT' value='789'> My property address</td></tr>
</table>
<input type="submit">
</form>

choo_chu
0
 
ZvonkoSystems architectCommented:
Better choice had been to split points for the support you received from third.
If you like I can ask for question reopen for the new points assignment?
0
 
hmaloneyAuthor Commented:
Ah, okay, I didn't know that you could split points.  My mistake.  Yes, if you could re-open I will do exactly what you suggest.
Cheers,
Heather
0
 
ZvonkoSystems architectCommented:
OK, I did it: http:Q_21877434.html
0
 
hmaloneyAuthor Commented:
I can't seem to do any point splitting.... sorry.
0
 
ZvonkoSystems architectCommented:
Thanks ai.
0
 
ZvonkoSystems architectCommented:
Thanks Heather.
See you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now