1

Is there a way to link to a form using only HTML/CSS? I am still a beginner in web dev and have not yet started on JavaScript or JQuery. So what I want to do is,

<div>
   <ul>
     <a href="??" target="_parent">
       <li class="toggle1">Guest</li>
     </a>
     <a href="??">
       <li class="toggle2">Owner</li>
     </a>
  </ul>
</div>

...in the tags in the I want to link to a form which has elements like First name, Last name etc, such that when I click on "Guest" the form for the guest should appear and likewise for "Owner"

user2948246
  • 75
  • 4
  • 10

2 Answers2

2

There is! Make the href tags to #guestform and #ownerform. Then, make each form's id attribute those values (guestform and ownerform). This looks like so:

<div>
<ul>
 <a href="#guestform">
   <li class="toggle1">Guest</li>
 </a>
 <a href="#ownerform">
   <li class="toggle2">Owner</li>
 </a>
</ul>
</div>

<form id="guestform">...</form>

<form id="ownerform">...</form>

Then, in the css, do the following:

form {
    display:none;
}

form:target {
    display:block;
}

Hope this helped you!

EDIT: As sdcr said, the a tag should be inside the li, and not the other way around for it to be semantically correct. It should be like this instead

<div>
<ul>
   <li class="toggle1">
    <a href="#guestform">Guest</a>
   </li>
   <li class="toggle2">
    <a href="#ownerform">Owner</a>
   </li>
</ul>
</div>
Community
  • 1
  • 1
kabiroberai
  • 2,930
  • 19
  • 34
  • A ` – steveax May 28 '15 at 04:33