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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel button

Status
Not open for further replies.

Marmalade

Technical User
Jan 30, 2002
29
US
I've included a "Cancel" button on a form that posts to an ASP page for processing, and which uses JavaScript for form validation. The "Cancel" button uses the following code:

<input type = button onclick='javascript: history.back(1)' value=&quot;cancel&quot;>

When I click on the button, however, nothing happens. I've used several variations on the code above, and can't get it to work. Does anyone have any ideas?

Thanks!
 
dont put any spaces between type = button ie

<input type=button onclick='javascript:history.back(1)' value=&quot;cancel&quot;>
 
Try this:
<input type=button onclick='javascript:history.back(-1)' value=&quot;cancel&quot;> I have not failed; I merely found 100,000 different ways of not succeding...
 
hi Marmalade,

back() does not take any arguments - this should work:

<input type = button onclick='history.back();' value=&quot;cancel&quot;>

this will also work:

<input type = button onclick='history.go(-1);' value=&quot;cancel&quot;>
======================================

if (!succeed) try();
-jeff
 
history.back() doesn't take any arguments. history.go() uses positive or negative numbers for arguments.
 
doesn't history.go(-1) work more widly as well?
I think I remember this coming up once. may be wrong though [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
OK
I meant browser compatibility [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Thanks, everyone - the button works beautifully now! I have noticed something strange, though; my JavaScript routines never execute in my development environment (I run my test pages on a PC workstation running IIS). They work just fine in my production environment, however. Anyone know why that might be the case? I thought my workstation IIS would automatically have a JavaScript engine, but could I be wrong?

Thanks again,

M
 
Marmalade,

javascript is executed client-side in the browser. it does not matter if you are using a webserver such as IIS. can you post the code for the routines have you written that are not working?

check this in your development environment:

<html><body onload=&quot;alert('hello')&quot;></body></html>

======================================

if (!succeed) try();
-jeff
 
Thanks, Jeff; I should have realized that my webserver wouldn't have anything to do with JavaScript execution!

I saved the alert(hello) snippet to a standard HTML file, and it worked perfectly in my development environment. For some reason, however, the JavaScript embedded in my ASP pages *won't* run on development. Here's an example of a function that I use for form validation on a login page:

Code:
<script language=javascript type=&quot;text/javascript&quot;>

<!-- Hide script from older browsers

// This script alerts the user if s/he forgets to enter a username or password

function validForm(passForm) 
	{
	if (passForm.Username.value == &quot;&quot;)
		{
		alert(&quot;Please enter a username&quot;)
		passForm.Username.focus()
		return false
		}
	if 	(passForm.Password.value == &quot;&quot;)
		{
		alert(&quot;Please enter a password&quot;)
		passForm.Password.focus()
		return false
		}
	return true
	}
	// End hiding script -->

The FORM tag looks like this (please disregard the VBScript, which is included for ASP purposes - unless you think that's part of the problem!):

Code:
<FORM onSubmit=&quot;return validForm(this)&quot; ACTION=&quot;CheckLogin.asp
<% If Request(&quot;SecondTry&quot;)=&quot;True&quot; Then  Response.Write &quot;?SecondTry=True&quot; End If %>&quot; METHOD=&quot;POST&quot;>

Aside from this material, the page includes a link to a style sheet, and the form elements themselves (which also contain some VBScript for ASP purposes) - but that's it.


-M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top