Solved

Show Hide span tag on checkbox selection

Posted on 2007-11-16
3
808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

636 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