Solved

Show Hide span tag on checkbox selection

Posted on 2007-11-16
3
805 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

777 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