Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCarel Du Plessis
Courses Plus Student 16,356 PointsCan elements have the same value if the used (names or vlaues or other)
I know you can not have the same id value but can you use names or values instead to have the same vlaue.
for example:
<ul> <li ><a href="#home" >Home</a></li> <li class="dropdown"> <a href="javascript:void(0)" class="dropbtn">Products</a> <div class="dropdown-content"> <a href="Products.php" name="INJECTION_MOLDS" onclick="myFunction1()">INJECTION MOLDS</a> <a href="Products.php" name="BLOW_MOLDS" onclick="myFunction2()">BLOW MOLDS</a> <a href="Products.php" name="DIECAST" onclick="myFunction3()">DIECAST</a> <a href="Products.php" name="AUTOMOTIVE" onclick="myFunction4()">AUTOMOTIVE</a> <a href="Products.php" name="GENERAL" onclick="myFunction5()">GENERAL</a> </div> </li> <li><a href="#home">Services</a></li> <li class="dropdown"> <a href="javascript:void(0)" class="dropbtn">Gallery</a> <div class="dropdown-content"> <a href="HTML Pages/GALLERY.html" name="INJECTION_MOLDS" onclick="myFunction1()">INJECTION MOLDS</a> <a href="HTML Pages/GALLERY.html" name="BLOW_MOLDS" onclick="myFunction2()">BLOW MOLDS</a> <a href="HTML Pages/GALLERY.html" name="DIECAST" onclick="myFunction3()">DIECAST</a> <a href="HTML Pages/GALLERY.html" name="AUTOMOTIVE" onclick="myFunction4()">AUTOMOTIVE</a> <a href="HTML Pages/GALLERY.html" name="GENERAL" onclick="myFunction5()">GENERAL</a> </div> </li> <li><a href="#home">About Us</a></li> <li><a href="#news">Contact Us</a></li> </ul>
<script> function myFunction1() { var x1 = document.getElementByName("INJECTION_MOLDS"); x1.name; localStorage.setItem("Products_Navigation",x1.name); } function myFunction2() { var x2 = document.getElementByName("BLOW_MOLDS"); x2.name; localStorage.setItem("Products_Navigation",x2.name); } function myFunction3() { var x3 = document.getElementByName("DIECAST"); x3.name; localStorage.setItem("Products_Navigation",x3.name); } function myFunction4() { var x4 = document.getElementByName("AUTOMOTIVE"); x4.name; localStorage.setItem("Products_Navigation",x4.name); } function myFunction5() { var x5 = document.getElementByName("GENERAL"); x5.name; localStorage.setItem("Products_Navigation",x5.name); }
</script>
1 Answer
Steven Parker
231,275 PointsI'm not sure what part of this code you are referring to, but while "id" properties must be unique on the page, you can indeed re-use a "name" setting as much as you like.
There's also no uniqueness requirements for "value" properties, but remember that these are only found on input control elements.