This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes div not woking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "div not woking" Watch "div not woking" New topic
Author

div not woking

manik kant
Greenhorn

Joined: Mar 24, 2008
Posts: 11
Hello All!!!

can any one please help me out!!

actually the following div is not working i cant get why??



<select name="section" onChange="javascript:show('section');">
<option value="null"></option>
<option value="1">1</option>
</select>

<div id="section" style="display:none; width:270;" >

<table>
<tr>
<th>Section<span class="mandatory">(*)</span></th>
<th>Venue<span class="mandatory">(*)</span></th>
<th>Number of Trainees<span class="mandatory">(*)</span></th>
<th>Number of Invigilators <span class="mandatory">(*)</span></th>
<th>Number of Extra Invigilators at submission </th>
</tr>
<tr>
<td>
<input type="text" name="section" value="" size="15" disabled="disabled">
</td>

<td>
<input type="text" name="venue" value="" size="15">
</td>

<td>
<input type="text" name="noOfTrainees" value="" size="6">
</td>

<td>
<input type="text" name="noOfInvigils" value="" size="4">
</td>

<td>
<input type="text" name="noOfExtraInvigils" value="" size="4">
</td>
</tr>
</table>

</div>



//this is the js function
<script>

function show(tabName) {

if(document.getElementById(tabName).style.display == "none")
{
document.getElementById(tabName).style.display = "block";
}
else if(document.getElementById(tabName).style.display == "block")
{
document.getElementById(tabName).style.display = "none";
}
}

</script>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Originally posted by manik kant:
actually the following div is not working i cant get why?
What do you mean by "not working"? Does it burst into flames?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Also, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Welcome to Javaranch.

I have tried your code in Mozilla firefox it works fine for me.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
manik kant
Greenhorn

Joined: Mar 24, 2008
Posts: 11
its not the case dear but onchange it is not opened


Originally posted by Bear Bibeault:
What do you mean by "not working"? Does it burst into flames?
manik kant
Greenhorn

Joined: Mar 24, 2008
Posts: 11
sir

thanks a lot for your pain but i am not getting then what can be the case with IE??

others are working fine but this is not

Originally posted by Muhammad Saifuddin:
Welcome to Javaranch.

I have tried your code in Mozilla firefox it works fine for me.
Mehul Wani
Greenhorn

Joined: Mar 18, 2008
Posts: 18
Hi,

I don't know what exactly you are trying to do. I guess you wish to show/hide the div based on the input selected in the select box(Please correct me if I'm wrong).

If the case as above, then you can simply use the visiblity parameter of style attribute of <div> as ---

Hide: document.getElementById(divId).style.visibility="hidden"
Show: document.getElementById(divId).style.visibility="visible"

Hope this helps you!!!
manik kant
Greenhorn

Joined: Mar 24, 2008
Posts: 11
Hello and thanks alot for yopur help but the problem is that its not entering the if block.

it does enter the function but on changing the value from drop down div is not displayed.

i tried urs also but not working.
Mehul Wani
Greenhorn

Joined: Mar 18, 2008
Posts: 18
Yes, definitely it won't enter the if block because it does not return the value you are comparing in the if statement.

If you put an alert before if as shown you will easily come to know what is the value here's the code:

function show(tabName) {
//Add this line and you will come to know why it is not working
//alert(document.getElementById(tabName).style.display);
if(document.getElementById(tabName).style.display == "none")
{
document.getElementById(tabName).style.display = "block";
}
else if(document.getElementById(tabName).style.display == "block")
{
document.getElementById(tabName).style.display = "none";
}
}
Mehul Wani
Greenhorn

Joined: Mar 18, 2008
Posts: 18
Oops!!! Sorry!! Just a correction in previous post's code
Uncomment the alert line

function show(tabName) {
//Add this line and you will come to know why it is not working
alert(document.getElementById(tabName).style.display);
if(document.getElementById(tabName).style.display == "none")
{
document.getElementById(tabName).style.display = "block";
}
else if(document.getElementById(tabName).style.display == "block")
{
document.getElementById(tabName).style.display = "none";
}
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: div not woking
 
Similar Threads
jQuery not working on page
jquery accordion is causing jquery treeview picker to breakup
Ajax, Struts, and a few pesky event based issues
How to pass values from struts select tag to another struts tag?
help with validation/ 2 functions on submit.