/    Sign up×
Community /Pin to ProfileBookmark

Hi All! Happy Halloween!

How Do I make a link in JavaScript, that will take them back to the referring page?

Ok, I have a form processor. If you hit submit while there are fields that are empty, it takes you to an error page. I want the error page to have a link to take you back to the referring page.

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@deep_dhyaniOct 31.2005 — use this script in action page

document.write("<a href='"+document.referrer+"'>Back</a>");
Copy linkTweet thisAlerts:
@comptech520authorOct 31.2005 — what do you mean by action page?
Copy linkTweet thisAlerts:
@deep_dhyaniOct 31.2005 — if you are using same page for form validation where you made the form. then put the script same page,

if you are using separate page for form validation then put the script in target page where you set the form target
Copy linkTweet thisAlerts:
@deep_dhyaniOct 31.2005 — if you are using same page for form & validation you can use :


<?php

if($submit_form=="Submit"){

if($fname==""){

echo "<b>Error:</b><br> -Name Field is empty !<br>";

echo "<center><A href='$_SERVER[SCRIPT_NAME]'>Back</A></center>";

exit();

}else{

echo "Form has been submitted !";

echo "<center><A href='index.php'>Home</A></center>";

exit();

}

}

?>

<html>

<Head>

</Head>

<body>

<Form action="<?PHP echo $_
SERVER['SCRIPT_NAME'];?>" Method="post">

Name : <input type="text" name="fname">

<input name="submit_form" type="submit" value="Submit">

</Form>

</Body>

<html>
×

Success!

Help @comptech520 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...