Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Show/hide form with js - little issue

Featured Replies

Hi,

I have a huge contact form which I did keep 'tidy' using an accordion style show/hide.

 

However, I've changed that now to have an inline list with hyperlinks which show/hide the divs containing the different sections of the form so the idea is that the user works from left to right through the links till the end of the form.....

 

However, ideally, i'd like a "Next >" link in the bottom right corner of each div to take the user to the next div of the form.....but it's not working. I'm using the same id as the hyperlink - could that be causing the problem?

 

Also - I'd like the first div to be shown on page load....

The duplicated ID's is probably causing the problem, without looking at it i can't really tell.

 

As for showing the first section on load, you could write a few lines to open that on page load. You could code it to be open by default (probably) or you could code the script to load anchor information on load. This also means you'd be able to link to a specific section of the form by amending the anchor information.

 

For utilising anchors, jQuery History is very useful. http://tkyk.github.com/jquery-history-plugin/

  • Author

I suspected it could be.....Although when I use a 'back to the top' link, it's duplicated on the page which is why I discarded that idea.

 

I'll have another go at it and come back if I still can't get it working.

 

Thanks for the link.

  • Author

I've sorted this by giving the 'next' links a different id and duplicating the js code.

 

Now I want to try and do something else....

 

I'd like an inline 'menu' at the top of the form highlighting which section of the form the user is on i.e. personal details, income details etc.....

 

Anyone know how that can be done?

I've sorted this by giving the 'next' links a different id and duplicating the js code.

 

Now I want to try and do something else....

 

I'd like an inline 'menu' at the top of the form highlighting which section of the form the user is on i.e. personal details, income details etc.....

 

Anyone know how that can be done?

 

If you give me 30 mins I'll try mock something up. Although I'm not great with js. :p

 

EDIT: Is this what you were looking for? :)

 

<!DOCTYPE HTML>
<html>
<head>
<title>Untitled Document</title>

<style>

body {
font-family: Arial, Helvetica, sans-serif;
color: #222;
}

.menuItem {
color: #DDD;
}

</style>

<script type="text/javascript">

function showMenu(selection) {

document.getElementById(selection).style.color = '#000';

}

function hideMenu(selection) {

document.getElementById(selection).style.color = '#DDD';

}

</script>
</head>

<body>

<form action="#" method="post">

Currently Selected: <span id="txtboxMenu" class="menuItem">Text Box</span> - <span id="passboxMenu" class="menuItem">Pass Box</span>
   <br />
   <br />
Text Box: <input type="text" name="txtbox" id="txtbox" onFocus="showMenu('txtboxMenu')" onBlur="hideMenu('txtboxMenu')" />
   <br />
   Password Box: <input type="password" id="passbox" onFocus="showMenu('passboxMenu')" onBlur="hideMenu('passboxMenu')" />
   <br />
   <input type="submit" name="submit" />

</form>

</body>
</html>

  • Author

Hey - I've managed to hash something together but I doubt it's perfect. Have to go out so I'll try that code later - many thanks!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.