JavaScript Newbie - problem with style="display:" toggle

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Nov 2008
Posts: 4
Reputation: Yipyo is an unknown quantity at this point 
Solved Threads: 0
Yipyo Yipyo is offline Offline
Newbie Poster

JavaScript Newbie - problem with style="display:" toggle

 
0
  #1
Dec 1st, 2008
I've got a simple function that that toggles the display of certain form fields. When I refresh the page, or post back, the display.value goes back to the original state. I don't know how to keep it on the selected state for refreshes and post backs. Please help. It's driving me crazy!

The javascript function:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function check_suspension()
  2. {
  3. q = document.getElementById('suspension_0').checked;
  4. if (q)
  5. {
  6. document.getElementById('spdate').style.display='';
  7. }
  8. else
  9. {
  10. document.getElementById('spdate').style.display='none';
  11. }
  12. }

The html code:


<tr class="row_even2">
<td class="td_left_small" style="width:177px;">
Suspension within 5 years?
</td>
<td style="text-align:left;padding-left:10px;">
<input id="suspension_0" name="Suspension" onchange="check_suspension();" type="radio" value="1"/>
<span style="cursor: default;">Yes</span>
<input id="suspension_1" name="Suspension" onchange="check_suspension();" type="radio" value="0"/>
<span style="cursor: default;">No</span>
</td>
</tr>
<tr class="row_even2" id="spdate" style="display: none;">
<td class="td_left_small" style="width:177px;">
Date of the suspension:
</td>
<td style="text-align:left;padding-left:10px;">
<input maxlength="2" name="SuspensionMonth" size="24" style="width: 20px" type="text" value=""/>&nbsp;/&nbsp;
<input maxlength="2" name="SuspensionDay" size="24" style="width: 20px" type="text" value=""/>&nbsp;/&nbsp;
<input maxlength="4" name="SuspensionYear" size="24" style="width: 40px" type="text" value=""/>
</td>
</tr>
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: Yipyo is an unknown quantity at this point 
Solved Threads: 0
Yipyo Yipyo is offline Offline
Newbie Poster

Re: JavaScript Newbie - problem with style="display:" toggle

 
0
  #2
Dec 1st, 2008
Ok. Monday Detail. Make sure that style="display:none;" isn't in the table tags, and I changed onchange= to onclick=.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: Yipyo is an unknown quantity at this point 
Solved Threads: 0
Yipyo Yipyo is offline Offline
Newbie Poster

Re: JavaScript Newbie - problem with style="display:" toggle

 
0
  #3
Dec 1st, 2008
Yeah... That didn't work either. I just used a php if statement to toggle it and save the post values.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 1672 | Replies: 2
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC