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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:46:08+00:00 2026-06-15T19:46:08+00:00

I want to create a javascript for checking value of textbox so if the

  • 0

I want to create a javascript for checking value of textbox so if the textbox blank, it won’t proceed to next page. AND after checking (if all condition is true) it will return the result of textbox.

I’ve created this javascript:

function cekdata(myform)
{
    var id = document.myform.clientid.value;
        var nama = document.myform.nama.value;
        var divisi = document.myform.divisi.value;
        var way = document.getElementById('twoway').value;
        var ori = document.myform.lokasi.value;
        var desti = document.myform.tujuan.value;
        var ket = document.myform.keterangan.value;
        var tpergi = document.myform.tglb.value;
        var jpergi = document.myform.jamb.value;
        var mpergi = document.myform.menitb.value;
        var pegi = tpergi+', '+jpergi+':'+mpergi;
        var tplg = document.myform.tglp.value;
        var jplg = document.myform.jamp.value;
        var mplg = document.myform.menitp.value;
        var plg = tplg+', '+jplg+':'+mplg;
  if (document.myform.clientid.value == "")
  {
    alert("Please Fill Your ID");
    myform.clientid.focus();
    return false;
  }
  else
  if (document.myform.nama.value == "")
  {
    alert("Please Fill Passenger Name");
    myform.nama.focus();
    return false;
  }
  else
  if (document.myform.lokasi.value == "")
  {
    alert("Please Fill Origin Location");
    myform.lokasi.focus();
    return false;
  }
  else
  if (document.myform.tujuan.value == "")
  {
    alert("Please Fill Your Destination");
    myform.tujuan.focus();
    return false;
  }
  else
  if (document.myform.tglb.value == "")
  {
    alert("Please Fill Departure Date");
    myform.tglb.focus();
    return false;
  }
  else
  if (document.myform.novehicle.value == "")
  {
    alert("Please Fill Vehicle Number");
    myform.novehicle.focus();
    return false;
  }
  else
  if (document.myform.driverid.value == "")
  {
    alert("Please Fill Driver ID");
    myform.driverid.focus();
    return false;
  }
  else
  if(document.getElementById('twoway').checked)
  {
      if (document.myform.tglp.value == "")
      {
        alert("Please Fill Return Date");
        myform.tglp.focus();
        return false;
      }
      else
      if (document.myform.tglb.value > document.myform.tglp.value)
      {
        alert("Return date must bigger than departure date");
        myform.tglp.focus();
        return false;
      }
  }
  else
  {
        var a = window.confirm("CONFIRMATION :\nID : " +id+"\nName : "+nama+"\nDivision : "+divisi+"\nOne Way : "+way+"\nOrigin : "+ori+"\nDestination : "+desti+"\nNotes : "+ket+"\nDeparture : "+pegi+"\nArrived :"+plg);
        if (a==true)
        {
            return true;
        }
        else
        {
            return false;
        }
  }
}

And I called this function like this:

<form name="myform" onsubmit="return cekdata(this);" method="POST" action="<?php $_SERVER["PHP_SELF"]; ?>">

But what I got is the confirm box never show up, and it returns true (and go to next page). So, how to change this condition so my confirmation box showed up first, then after click OK, it go to next page, and if CANCEL, do nothing?

  • 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-15T19:46:09+00:00Added an answer on June 15, 2026 at 7:46 pm
    *Just make slight changes in your javascript just passevent on form submit*
    
    
    <input type="submit" value="Submit" name="submit" onClick="return cekdata(this,event);" />
    

    and when your textbox is empty or null write event.preventDefault() instead of return false;

    function cekdata(myform,evt)
    {
    var id = document.myform.clientid.value;
        var nama = document.myform.nama.value;
        var divisi = document.myform.divisi.value;
        var way = document.getElementById('twoway').value;
        var ori = document.myform.lokasi.value;
        var desti = document.myform.tujuan.value;
        var ket = document.myform.keterangan.value;
        var tpergi = document.myform.tglb.value;
        var jpergi = document.myform.jamb.value;
        var mpergi = document.myform.menitb.value;
        var pegi = tpergi+', '+jpergi+':'+mpergi;
        var tplg = document.myform.tglp.value;
        var jplg = document.myform.jamp.value;
        var mplg = document.myform.menitp.value;
        var plg = tplg+', '+jplg+':'+mplg;
    if (document.myform.clientid.value == "")
    {
    alert("Please Fill Your ID");
    myform.clientid.focus();
    

    evt.preventDefault();
    }

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

Sidebar

Related Questions

I want to create a string in JavaScript that contains all ascii characters. How
I want to create a JavaScript popup on a current page so when a
I want to create a JavaScript function that parses my HTML page, get the
I want to create an entire page through javascript i.e when i give a
I want to insert different url's dynamically after checking a condition Here's the pseudocode
I want to create with Javascript some controls inside a form and then I
I want to create a Javascript class/object that allow me to have various method:
I want to create a simple Javascript program with a HTML interface. The program
I use embedded SVG in XHTML and want to create animations from Javascript, but
Basically I want to create one large object of many object in JavaScript. Something

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.