Solved

Show Hide span tag on checkbox selection

Posted on 2007-11-16
3
804 Views
Last Modified: 2010-04-21
Quite simple question for a javascript expert I'm sure; I want to be able to show an extra input field with his label if the user check a checkbox

<input type="checkbox" name="slabed[]" value="1"> <b>Slabed</b> <span><b>By</b><input type="text" name="slabedby[]"></span>

some details: Dynamic form
                      within a PHP script
                      could have more than one field hence the bracket [] for making array of the form submission.
                      Has to work in all major Browsers
                      The input field inside the tag might turn out to be a dropdown instead, not sure yet.
0
Comment
Question by:gamebits
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 20302667
Like this:



<span><input type="checkbox" name="slabed[]" value="1" onClick="checkBox(this)" > <b>Slabed</b> <span style="display:none;"><b>By</b><input type="text" name="slabedby[]"></span></span>
<script>
function checkBox(theBox){
  var theSpan = theBox.parentNode;
  theSpan = theSpan.getElementsByTagName("span")[0];
  theSpan.style.display=(theBox.checked)?"inline":"none";
}
</script>


For the select open please a new question.

0
 
LVL 28

Author Closing Comment

by:gamebits
ID: 31409693
Awsome, look for the other question it will be posted shortly.
0
 
LVL 28

Author Comment

by:gamebits
ID: 20302706
Awsome

Thanks

Look for the other question it will be posted shortly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now