Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

switch pics/hide section

Status
Not open for further replies.

ttuser4

MIS
Jun 19, 2008
147
CA
hi, i have these two functions:

function valfrp(chk){
if (chk.checked == 1){
document.getElementById(frp1).style.display = 'none';
document.getElementById(frp1).style.display = 'block';
document.getElementById(frp1).style.display = 'none';
}
}

function valfrd(chk){
if (chk.checked == 0)
document.getElementById(frdim).style.display = 'none';

html

<input type="checkbox" onclick="showhide('poolfr1');showhide('poolfr2');valfrd(C1, frdim);" name="C1" onchange="valfrp('C1');" value="ON" />

...

<div id="frdim" style="display:none">
<table border="0" width="100%">
<tr> <td>A:
<INPUT type="text" name="T20" size="20"></td> <td>B:
<INPUT type="text" name="T21" size="20"></td> <td>C:
<INPUT type="text" name="T22" size="20"></td> <td>D:
<INPUT type="text" name="T23" size="20"></td>
</tr>
</table>

...

</table> </td> <td>
<img border="0" src="pics/u123.png" width="255" height="152" id="frp1" />
<img border="0" src="pics/u149.png" width="255" height="152" id="frp2" style="display:none;" />
<img border="0" src="pics/u184.png" width="255" height="152" id="frp3" style="display:none;" /></td>
</tr>
</table>


}


I need help with those two functions; they don't do what I want to do - switch pics and hide one section/table.
any ideas please?
 
any ideas please?

Many...

- Your checkboxes have a "name" attribute of "C1", but you are trying to refer to the checkboxes using "getElementById" when they have no "id" attribute.

This sort of sloppy practice might work in IE, but any good browser (IMHO) should block this and force programmers to do a proper job.

- Your "onclick" attribute calls the "valfrd" function with two variables, C1 and frdim. Given these are not in quotes, you need to ensure that these variables exist and contain something meaningful.

- Your "valfrd" function has no closing brace, so presumably either you're not giving us all of the code, or you have loads of syntax errors.

My recommendations:

1) Ensure the HTML validates.
2) Run the page in Firefox and fix any errors that show up in the JavaScript console.

If after those 2 steps you still have problems, post the code (enclosed in [ignore]
Code:
[/ignore] tags) or a URL to an online version of the page.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks.
I fix one function:

function valfrd(chk){
if (chk.checked == 0)
document.getElementById('frdim').style.display = 'none';
}

the problem was missing apostrophe in getElementById('frdim')


The other function:
function valfrp(chk){
if (chk.checked == 1){
document.getElementById('frp1').style.display = 'none';
document.getElementById('frp1').style.display = 'block';
document.getElementById('frp1').style.display = 'none';
}
}

still doesn't work.
"getElementById" in this function refers to ids of images I want to hide/show (they exist):
<td>
<img border="0" src="pics/u123.png" width="255" height="152" id="frp1" />
<img border="0" src="pics/u149.png" width="255" height="152" id="frp2" style="display:none;" />
<img border="0" src="pics/u184.png" width="255" height="152" id="frp3" style="display:none;" /></td>

not to the checkbox

 
sorry this is the actual code:
function valfrp(chk){
if (chk.checked == 1){
document.getElementById('frp1').style.display = 'none';
document.getElementById('frp2').style.display = 'block';
document.getElementById('frp3').style.display = 'none';
}
}
 
If you still have the problem, I suggest you go back and re-read my post, as I've seen no evidence to show you've taken any of it in whatsoever.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top