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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simply call javascript code

Status
Not open for further replies.

MCasey

Technical User
May 30, 2006
21
US
Can someone tell me how I can call this javascript to hide two divs (info1 and info2)? This works, but it looks cumbersome...

Sorry, I'm working in DW and don't know much about scripting...

<a href="javascript:;" onClick="MM_callJS('hide(\'info1\')');MM_callJS('hide(\'info2\')')">test</a>

Thanks!


 
You can do this:
Code:
<a href="javascript:;" onClick="document.getElementById('info1').style.display = 'none');document.getElementById('info2').style.display = 'none'">test</a>

Or you can do this:

Code:
<a href="#" onclick="hideDivs(); return false">test</a>

and create a function withing <script> tags:

Code:
<script type="text/javascript">
function hideDivs() {
   document.getElementById("info1").style.display = "none";
   document.getElementById("info2").style.display = "none";
}
</script>

Typically, you want to put your <script> tags in the <head> section of your HTML, though there are sometimes exceptions.

<.

 
Thanks, I'll try those ideas.

Is it possible to call two different divs using commas like this:

<a href="javascript:;" onClick="MM_callJS('hide('info1', 'info2')');">test</a>
 
All parameters passed to a function are available in an arguments array, so you could do the following:

<a href="javascript:;" onClick="return hide('info1', 'info2');">test</a>

function hide() {
for (var i=0; i<arguments.length; i++)
document.getElementById(arguments).style.display = 'none';
return false;
}

Not sure what you MM_callJS function is but it seems to be making the call more complicated than it needs to be.

Alternatively, you could pass in an array of values.

Chaz
 
And adds the complication of more than 2 levels of quotation marks. MCasey's last example won't work because of that.

Lee
 
thanks you guys...I got it working...now I just need to simplify it. this really helped!
 
I'm with you, monksnake. I've had to repair too many DW-produced sites that were a nightmare.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top