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!

New Window w/ Form Submission 1

Status
Not open for further replies.

mrDrive

MIS
Aug 29, 2002
94
0
0
US
Hi,

I have a form that is being built dynamically with a recordset.

Code:
<form name='frmReportGen' action='report.asp' method='post'>
<input type='checkbox' name='chkAddToReport' value='" & objRS("ID") & "'>
.
.
.
<input type="submit" value="Generate Report" onclick="validateForm(); return false;">
</form>

When the user submits the form, it generates a report built from which items the user checked in the form (e.g. it builds a recordset based on which IDs (checkboxes) were selected). I want the report to open in a new window. Here lies the problem.

I can get the report to open in a new window, but it ignores any checkboxes that were selected. The report generates correctly when I target the same window. You can see I'm also checking to make sure at least one checkbox was selected too.



Thanks for any help!

Code:
function validateForm() {
	var checkFound = false;
	for (var counter=0; counter < document.forms['frmReportGen'].length; counter++) {
		if (document.forms['frmReportGen'].elements[counter].checked == true) {
			checkFound = true;
		}
	}
	if (checkFound != true) {
		alert("You must check at least one item before running a report!");
		return false;
	} else {
		document.forms['frmReportGen'].target = 'myRptWin';
		var winLeft = (screen.width - 800) / 2;
		var winTop = (screen.height - 675) / 2;
		windowName = "myRptWin";
		var windowFeatures = "width=800,height=675,status,scrollbars,resizable,left=" + winLeft + ",top=" + winTop 
		newWindow = window.open('report.asp', windowName, windowFeatures);
		newWindow.focus();
	}
}
 
What is this:

Code:
    for (var counter=0; counter < document.forms['frmReportGen'].length; counter++) {
        if (document.forms['frmReportGen'].elements[counter].checked == true) {
            checkFound = true;
        }
    }

Supposed to be doing?

Forms[''].length should give you a value of 1.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That (supposedly?) loops through all the checkboxes in the form and indicates whether or not there are no checkboxes checked. There can be possibly many checkboxes in the form.
 
If you don't mind a slight re-write...

Code:
var checkFound = false;

// get all form elements
var els = document.forms['frmReportGen'].elements;

// loop through each element
for (var i = 0; i < els.length; i++) {
    // if this element is a checked checkbox
    if (els[i].type == 'checkbox' && els[i].checked)
        checkFound = true;
}

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Take this simple example:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>

<script>
function doSomething(f) {
    var w = window.open('','myWin','height=400,width=400');
    f.target = 'myWin';
}
</script>

</head>

<body>

<form name="f" onsubmit="doSomething(this);">
<input type="submit" />
</form>


</body>
</html>

It works fine. Try opening the window first. And there's really no need to open it to "report.asp" since I assume you're calling this from the onsubmit event of the form.

Am I correct?

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks much for the help...

Yes, I am still getting the same error...

Here's the source of the page that generates the form:

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="includes/style.css" type="text/css" rel="stylesheet">
<script>
function validateForm() {
    var checkFound = false;

    // get all form elements
    var els = document.forms['frmReportGen'].elements;

    // loop through each element
    for (var i = 0; i < els.length; i++) {
    // if this element is a checked checkbox
        if (els[i].type == 'checkbox' && els[i].checked)
            checkFound = true;
    }
    if (checkFound != true) {
        alert("You must check at least one item before running a report!");
        return false;
    } else {
        document.forms['frmReportGen'].target = 'myRptWin';
        var winLeft = (screen.width - 800) / 2;
        var winTop = (screen.height - 675) / 2;
        windowName = "myRptWin";
        var windowFeatures = "width=800,height=675,status,scrollbars,resizable,left=" + winLeft + ",top=" + winTop
        newWindow = window.open('report.asp', windowName, windowFeatures);
        newWindow.focus();
    }
}
</script>
</head>

<body>

<div class="content">
<form name='frmReportGen' action='report.asp' method='post' target='myRptWin'>
<table width="100%" cellpadding="0" cellspacing="0" class="outline_tbl">
    <tr>
        <td><h3>Search Results</h3></td>

    </tr>

<tr>
    <td>
    <table width="100%" cellpadding="3" cellspacing="0" class="results_tbl" style="margin-bottom: 1em;">
        <tr>
            <th width="30%">Organization</th>
            <th width="15%" style="text-align: center;">State</th>
            <th width="15%">Category</th>

            <th width="30%">Date Added</th>
            <th width="10%" style="text-align: center;">Add to Report</th>
        </tr>
        
    <tr>
<td><a href='details.asp?needId=1' target='details'>blah</a></td>
<td align='center'>blah</td>
<td>blah</td>
<td>Fri&nbsp;3-Dec-04</td>

<td align='center'><input type='checkbox' name='chkAddToReport' value='1'></td>
</tr>
<tr>
<td><a href='details.asp?needId=2' target='details'>blah</a></td>
<td align='center'>blah</td>
<td>blah</td>
<td>Fri&nbsp;3-Dec-04</td>
<td align='center'><input type='checkbox' name='chkAddToReport' value='2'></td>
</tr>
</table>
    

            <tr>
                <td colspan="5" align="right" style="padding: 8px;">
                <input type="submit" value="Generate Report" onclick="validateForm(); return false;"></td>
            </tr>    
        </table>
    
    </td>

</tr>
</table>
</form>
</div>
</body>
</html>
 
Three slight changes got it working for me:

#1
Code:
newWindow = window.open([red]''[/red], windowName, windowFeatures);

#2
Code:
<form name='frmReportGen' ... [red]onsubmit="return validateForm();"[/red]>

#3
Code:
<input type="submit" value="Generate Report">

Try those changes.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That did it ("return validateForm();")...thank you very much!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top