Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:53:25+00:00 2026-06-17T10:53:25+00:00

I have a simple form on a website that contains two radio buttons, and

  • 0

I have a simple form on a website that contains two radio buttons, and I have added some Javascript form validation for when the neither of the radio buttons are clicked. (thanks SO) However when the user clicks the okay button the page is redirected to the “process” page for the form. I would prefer the behavior of just reloading the page or closing the alert box when the user clicks the “ok” button in the alert box.

To further see what I’m talking about you can go to chrisrjones.com which should redirect you to chrisrjones.com/splash.php then click enter. (without selecting a radio button) An alert box should appear, and once the okay button is pressed, the page redirects to the form process page (not what I want).

<!DOCTYPE html>

<html lang="en">

<head>
<title>chrisRjones.com - Splash</title>

 <?php
function getImagesFromDir($path) {
    $images = array();
    if ( $img_dir = @opendir($path) ) {
        while ( false !== ($img_file = readdir($img_dir)) ) {
            // checks for gif, jpg, png
            if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) {
                $images[] = $img_file;
            }
        }
        closedir($img_dir);
    }
    return $images;
}

function getRandomFromArray($ar) {
    mt_srand( (double)microtime() * 1000000 ); // php 4.2+ not needed
    $num = array_rand($ar);
    return $ar[$num];
}

/////////////////////////////////////////////////////////////////////
// This is the only portion of the code you may need to change.
// Indicate the location of your images 

$root = '';
// use if specifying path from root
//$root = $_SERVER['DOCUMENT_ROOT'];

$path = 'pics/';

// End of user modified section 
/////////////////////////////////////////////////////////////////////

// Obtain list of images from directory 
$imgList = getImagesFromDir($root . $path);
$img = getRandomFromArray($imgList);
?> 





<!-- begin google analytics PHP include -->

<?php include_once("analyticstracking.php") ?>

<!-- end google analytics PHP include -->

<!-- Javascript radiobutton form validation -->

<script type="text/javascript">
function valForm(form) {
    var btn1 = parseInt(form.splash.value, 10) || 0;
    btn = (btn1 )
    if (btn < 3) {
        alert('You either like splash pages or hate em, choose one ...please');
        return false; }
    else {
     alert('Button value ' + btn + ' selected');
    }
}
</script>

<!-- Javascript radiobutton form validation END -->


</head>

<body>
<img src="<?php echo $path . $img ?>" alt="" width="640" height="auto"  />
<h1>Hello Javascript redirection.</h1><br />
<p>

<form name="tosplashornottosplash" action="splash-process.php" method="post">
Splash pages are stupid 

<input type="radio" name="splash" value="false" /> No
<input type="radio" name="splash" value="true" /> Yes

<input type="submit" name="formSubmit" onClick="valForm(tosplashornottosplash)" value="Enter" />
</form>



</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:53:27+00:00Added an answer on June 17, 2026 at 10:53 am

    return false from valform in situations you want to stay on the same page.

    for example:

    function valForm(form) {
    var btn1 = parseInt(form.splash.value, 10) || 0;
    btn = (btn1 )
    if (btn < 3) {
       alert('You either like splash pages or hate em, choose one ...please');
       return false;
    }
    else {
         alert('Button value ' + btn + ' selected');
    } 
    }
    

    You may also need to change your markup as follows adding the return statement.

    <input type="submit" value="Enter" onclick="return valForm(tosplashornottosplash)" name="formSubmit">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple contact form on a website that has 2 text fields,
So I have a really simple form on a website that's entirely AJAX based
I have a simple PHP contact form on my website that I'm building. At
I have simple login form in my website. In given requirements stands, that password
Okay here's my situation. I have a php file that contains a simple form
I have a simple contact form on my website that sends an email to
There are some HTML based games (ie bootleggers.us) that have a simple login form
i have a website that has a simple login form. the form posts to
I have a website in which I have a very simple html form that
I have simple form like this which accepts only two values string action and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.