Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Trying to hide HTML Elements based on which radio button is clicked

I am trying to do something where you can search for flights within a database based on the departure/arrival airport and departure/return flight. There are two radio buttons where you can click whether it's round-trip or one-way. What I am having trouble with is, I want to hide the return flight thing whenever the one-way radio button has been clicked but it won't budge. Everything remains on screen no matter what button is pushed. Here is my code, any help would be appreciated!

<!DOCTYPE html>
<html>

<head>
<script>
function tripCheck(){
    if (document.getElementById('round').checked){
        document.getElementById('toggle').style.display = 'none';
    } else {
        document.getElementById('toggle').style.display = 'block';
    }
</script> 
</head>

<body>
<form action="/post" method="POST">

<!-- Radio Buttons -->
 <input type="radio" onclick="javascript:tripCheck();" name="oneround" id="round" checked>Round Trip
 <input type="radio" onclick="javascript:tripCheck();" name="oneround" id="oneway">One Way<br>

<!-- Source and Destination Locations -->
  <input type="text" name = "source" placeholder="Enter an origin" required/>
  <input type="text" name = "dest" placeholder="Enter a Destination" required/><br>

<!-- Departure and Return Dates -->
Departure Date:
  <input type="date" id="departure" name="ddate"
       value="mm/dd/yyyy" min="2000-01-01" max="2050-01-01" required>
  <div id="toggle">Return Date:
  <input type="date" id="return" name="rdate"
       value="mm/dd/yyyy" min="2000-01-01" max="2050-01-01"> 
  </div>

<!-- Submit Button -->
  <br>
  <input type="submit" value="Submit">
  
</form>
</body> 

</html>

What it looks like

What I want it to look like

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

<!DOCTYPE html>
<html>

<head>

</head>

<body>
  <form action="/post" method="POST">

    <!-- Radio Buttons -->
    <input type="radio" onchange="tripCheck()" name="oneround" id="round" checked>Round Trip
    <input type="radio" onchange="tripCheck()" name="oneround" id="oneway">One Way<br>

    <!-- Source and Destination Locations -->
    <input type="text" name="source" placeholder="Enter an origin" required/>
    <input type="text" name="dest" placeholder="Enter a Destination" required/><br>

    <!-- Departure and Return Dates -->
    Departure Date:
    <input type="date" id="departure" name="ddate" value="mm/dd/yyyy" min="2000-01-01" max="2050-01-01" required>
    <div id="toggle">Return Date:
      <input type="date" id="return" name="rdate" value="mm/dd/yyyy" min="2000-01-01" max="2050-01-01">
    </div>

    <!-- Submit Button -->
    <br>
    <input type="submit" value="Submit">

  </form>
  <script>
    function tripCheck() {
      if (!document.getElementById('round').checked) {
        document.getElementById('toggle').style.display = 'none';
      } else {
        document.getElementById('toggle').style.display = 'block';
      }
      }
  </script>
</body>

</html>

about 4 years ago · Juan Pablo Isaza Report

0

You have one error on the above code. Your function doesn't have the closing bracket. If you want to view javascript error you can right click and go to inspect or simply press f12 and go to console menu.

about 4 years ago · Juan Pablo Isaza Report

0

Try entering this, a function Travel_Control

 <script>
    function Travel_Control() {
      if (!document.getElementById('round').checked) {
        document.getElementById('toggle').style.display = 'none';
      } else {
        document.getElementById('toggle').style.display = 'block';
      } }
  </script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!