4 Replies - 20588 Views - Last Post: 16 October 2009 - 06:48 AM

#1 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

OnClick Export HTML table to Excel

Post icon  Posted 15 October 2009 - 11:25 AM

It's not working.

<FORM METHOD="POST" on click="java script:window.location.href='exporttoexcel.jsp ">
<INPUT NAME="Results"TYPE="submit" VALUE="Export to Excel">
</FORM>


Asp file:


<%
Response.ContentType = "application/x-download"
Response.AddHeader = ("content-disposition","attachment;filename=Test.xls")
%>


Is This A Good Question/Topic? 0
  • +

Replies To: OnClick Export HTML table to Excel

#2 ecuscotty  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 40
  • Joined: 14-October 09

Re: OnClick Export HTML table to Excel

Posted 15 October 2009 - 12:32 PM

View Postknockkneed81, on 15 Oct, 2009 - 10:25 AM, said:

It's not working.

<FORM METHOD="POST" on click="java script:window.location.href='exporttoexcel.jsp ">
<INPUT NAME="Results"TYPE="submit" VALUE="Export to Excel">
</FORM>


Asp file:


<%
Response.ContentType = "application/x-download"
Response.AddHeader = ("content-disposition","attachment;filename=Test.xls")
%>


Hello,

You have a bunch of extra spaces, a missing quote, and the onclick should be on the button, not the form. But really you don't need any javascript to do this. Try...

<FORM METHOD="post" action="exporttoexcel.asp">
<INPUT NAME="Results" TYPE="submit" VALUE="Export to Excel" />
</FORM>



If you need to call a javascript to validate the form you can ...

<script type="text/javascript">
validateExport = function(){
	 // validation code here...
	 if(valid){
		  return true;
	 } else {
		  return false;
	 }
}
</script>
<FORM METHOD="post" action="exporttoexcel.asp" onsubmit="validateExport();">
<INPUT NAME="Results" TYPE="submit" VALUE="Export to Excel" />
</FORM>



... And is "exporttoexcel" an ASP or a JSP page? Looks like it should be ASP?...
Was This Post Helpful? 0
  • +
  • -

#3 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: OnClick Export HTML table to Excel

Posted 16 October 2009 - 05:05 AM

View Postecuscotty, on 15 Oct, 2009 - 11:32 AM, said:

View Postknockkneed81, on 15 Oct, 2009 - 10:25 AM, said:

It's not working.

<FORM METHOD="POST" on click="java script:window.location.href='exporttoexcel.jsp ">
<INPUT NAME="Results"TYPE="submit" VALUE="Export to Excel">
</FORM>


Asp file:


<%
Response.ContentType = "application/x-download"
Response.AddHeader = ("content-disposition","attachment;filename=Test.xls")
%>


Hello,

You have a bunch of extra spaces, a missing quote, and the onclick should be on the button, not the form. But really you don't need any javascript to do this. Try...

<FORM METHOD="post" action="exporttoexcel.asp">
<INPUT NAME="Results" TYPE="submit" VALUE="Export to Excel" />
</FORM>



If you need to call a javascript to validate the form you can ...

<script type="text/javascript">
validateExport = function(){
	 // validation code here...
	 if(valid){
		  return true;
	 } else {
		  return false;
	 }
}
</script>
<FORM METHOD="post" action="exporttoexcel.asp" onsubmit="validateExport();">
<INPUT NAME="Results" TYPE="submit" VALUE="Export to Excel" />
</FORM>



... And is "exporttoexcel" an ASP or a JSP page? Looks like it should be ASP?...


It should be ASP, but which ever works.
Was This Post Helpful? 0
  • +
  • -

#4 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: OnClick Export HTML table to Excel

Posted 16 October 2009 - 05:23 AM

View Postknockkneed81, on 16 Oct, 2009 - 04:05 AM, said:

View Postecuscotty, on 15 Oct, 2009 - 11:32 AM, said:

View Postknockkneed81, on 15 Oct, 2009 - 10:25 AM, said:

It's not working.

<FORM METHOD="POST" on click="java script:window.location.href='exporttoexcel.jsp ">
<INPUT NAME="Results"TYPE="submit" VALUE="Export to Excel">
</FORM>


Asp file:


<%
Response.ContentType = "application/x-download"
Response.AddHeader = ("content-disposition","attachment;filename=Test.xls")
%>


Hello,

You have a bunch of extra spaces, a missing quote, and the onclick should be on the button, not the form. But really you don't need any javascript to do this. Try...

<FORM METHOD="post" action="exporttoexcel.asp">
<INPUT NAME="Results" TYPE="submit" VALUE="Export to Excel" />
</FORM>



If you need to call a javascript to validate the form you can ...

<script type="text/javascript">
validateExport = function(){
	 // validation code here...
	 if(valid){
		  return true;
	 } else {
		  return false;
	 }
}
</script>
<FORM METHOD="post" action="exporttoexcel.asp" onsubmit="validateExport();">
<INPUT NAME="Results" TYPE="submit" VALUE="Export to Excel" />
</FORM>



... And is "exporttoexcel" an ASP or a JSP page? Looks like it should be ASP?...


It should be ASP, but which ever works.


I tried that code and it is opening an empty excel file. I would like the excel file to contain the html table data that's on the webpage.
Was This Post Helpful? 0
  • +
  • -

#5 ecuscotty  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 40
  • Joined: 14-October 09

Re: OnClick Export HTML table to Excel

Posted 16 October 2009 - 06:48 AM

What is the code for your exporttoexcel.asp file? Does it not contain the table with its data?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1