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 6835581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:14:59+00:00 2026-05-26T23:14:59+00:00

I have a button known as Prepare Questions. Now when I click on this

  • 0

I have a button known as “Prepare Questions”. Now when I click on this button, this button does two things, using the validaton() function it validates the form so that if there is an error in the form (empty textbox and radio button not selected) then it displays the suitable error messages on the page. But also the button uses the “openSessionPopup” function so that it opens up a pop up window which states the word “Session”.

The problem is that when I click on the button it does both functions, so it displays validation errors if there is some and also opens up the pop up window.

What I want to do is that the pop up window should only be displayed after there are no validation errors. But I can’t seem to get this to work, does anyone else know how to do this.

Below is my code:

 <head>
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
            <title>Create a Session</title>
            <script type="text/javascript">

     function validation() {

                    var btnRadioO = document.getElementsByName("sessionNo");               
                    var isbtnRadioChecked = false;;

                    var dateTextO = document.getElementById("datepicker");
                    var timeTextO = document.getElementById("timepicker");


                    var errMsgO = document.getElementById("radioAlert");

                    var errDateTimeMsgO = document.getElementById("dateTimeAlert");
                    var errDateMsgO = document.getElementById("dateAlert");
                    var errTimeMsgO = document.getElementById("timeAlert");


                    for(i=0; i < btnRadioO.length; i++){
                        if(btnRadioO[i].checked){
                            isbtnRadioChecked = true;
                        }
                    }

                    if(!isbtnRadioChecked) {
                       errMsgO.innerHTML = "Please Select the Number of Sessions you Require";
                    } else {
                        errMsgO.innerHTML = "";
                    }                                

         if (dateTextO.value == ''){
                    errDateMsgO.innerHTML = "Please Select a Date";
                }else{
                    errDateMsgO.innerHTML = ""; 
                }

         if (timeTextO.value == ''){
                    errTimeMsgO.innerHTML = "Please Select a Time";
                }else{
                    errTimeMsgO.innerHTML = ""; 
                }
    }

                       function openSessionPopup (session) {
     window.open(session,
     'window',
     'width=500,height=500,scrollbars=yes,status=no');
     }

    </script>
    </head>

    <body>
    <form action="create_session.php" method="post">

     <table>
              <tr>
              <th>Number of Sessions :</th>
              <td class="sessionNo"><input type="radio" name="sessionNo" value="1" />1</td>
              <td class="sessionNo"><input type="radio" name="sessionNo" value="2" />2</td>
              <td class="sessionNo"><input type="radio" name="sessionNo" value="3" />3</td>
              <td class="sessionNo"><input type="radio" name="sessionNo" value="4" />4</td>
              <td class="sessionNo"><input type="radio" name="sessionNo" value="5" />5</td>
              </tr>
              </table>
              <div id="radioAlert"></div>
     <p><input type="text" id="datepicker" >
                <br/><span id="dateAlert"></span></p>
                <p><input type="text" id="timepicker" >
                <br/><span id="dateTimeAlert"></span><span id="timeAlert"></span></p>

<p><input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onClick="validation();openSessionPopup(this.href); return false"  /></p>
    </form>

    </body>
  • 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-05-26T23:14:59+00:00Added an answer on May 26, 2026 at 11:14 pm

    First you should move your event handlers out of your html markup.

    Next you should bind an event handler to that click event.

    After that you should modify your validation method to return true or false to denote if it passed validation or not.

    Last you should use that validation result in a conditional wrapping your showpopup method invocation.

    Something like

    function myClickHandler(){
         if(validation()){
            showSessionPopup();
         }
    }
    

    for your handler and this how how you would bind it

    document.getElementsByName("prequestion")[0].addEventListener('click', myClickHandler);
    

    Finally you would modify your validation method like so

    function validation() {
        var result = true;
                    var btnRadioO = document.getElementsByName("sessionNo");               
                    var isbtnRadioChecked = false;;
    
                    var dateTextO = document.getElementById("datepicker");
                    var timeTextO = document.getElementById("timepicker");
    
    
                    var errMsgO = document.getElementById("radioAlert");
    
                    var errDateTimeMsgO = document.getElementById("dateTimeAlert");
                    var errDateMsgO = document.getElementById("dateAlert");
                    var errTimeMsgO = document.getElementById("timeAlert");
    
    
                    for(i=0; i < btnRadioO.length; i++){
                        if(btnRadioO[i].checked){
                            isbtnRadioChecked = true;
                        }
                    }
    
                    if(!isbtnRadioChecked) {
                       errMsgO.innerHTML = "Please Select the Number of Sessions you Require";
                       result = false;
                    } else {
                        errMsgO.innerHTML = "";
                    }                                
    
         if (dateTextO.value == ''){
                    result = false;
                    errDateMsgO.innerHTML = "Please Select a Date";
                }else{
                    errDateMsgO.innerHTML = ""; 
                }
    
         if (timeTextO.value == ''){
                    errTimeMsgO.innerHTML = "Please Select a Time";
                    result = false;
                }else{
                    errTimeMsgO.innerHTML = ""; 
                }
    
         return result;
    }
    

    This will make your validation() method return false if you have errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I have one issue with UInavigationcontroller In my firstview i have button.If i click
Most of you might have known already that godaddy does'nt have any plugins or
I am in this situation where I have to display a button which says
Hey guys, I have this sign up script and I'm using mysql_real_escape_string .I know
I have this strange issue with my web app. You see, I'm using jQuery
Ok well I have been fighting with this for a while now and have
I have a pop up window function where when a button is clicked the
I have form with few buttons and I want to know what button is
I have button, which fires an event, that deletes a record from the database.

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.