Toggle function

This code worked in an old IE browser but I can’t get it to work in Edge, FF, Chrome.

The way it worked is that if you click it expands the question and shows you the answer and if you double click it opens in another window to edit. In the newer browsers, when you click it doesn’t open as distribed, but if you double click it does open the edit window.

Any help would be appreciated, thank you.

function toggle(id)
	if document.all ("info"&id).style.display="inline" then
		document.all ("info"&id).style.display="none"
		document.all ("info"&id).style.display="inline"
	end if
end function
<div id=question<%=id%> onclick="toggle(<%=id%>)"
	style="cursor:hand"><b>ID:<%=rsView("id")%></B> - <%=rsView("question")%></div>
<span name=info<%=id%> id=info<%=id%> style="display:none">

the script language= syntax is deprecated, so i wouldnt recommend using it… unless you have a very strong need for this to be vbscript, i would suggest translating it into actual Javascript.

I didn’t catch that, but it didn’t make any difference by using the regular script tag.

Well if you’re using a regular script tag, then it’s going to interpret the code inside it as if it were Javascript.

And that code isnt written in Javascript. So it’s going to fail.

Well I am confused - so if doesn’t work because it’s not JS, what do I use?

You use JS.

The browser uses JS. It understands JS. What you have inside your script tag is not JS. Make it JS.

At the very least, start by properly formatting the function and if statements. You’ve shown this forum that you were working with AJAX functions and jQuery notations. So… go ahead and give it a try and write the normal JS for a function and an if, and keep an eye on your assignment vs equality operators.

This is the best I could come up with but it’s still not right.

function toggle(id) {
	if document.getElementById ("info"&id).style.display="inline" {
		document.getElementById ("info"&id).style.display="none";
	return false;
		document.getElementById ("info"&id).style.display="inline" {
	return false;
end function

You’re getting there.
Things to work on:

  1. The test condition of an if should be wrapped in parentheses. if (xcondition) {
  2. = is an assignment. == is a comparator.
  3. Count your braces. {'s start a block, }'s end one; so every { should match up to a }.
  4. Concatenation in javascript is with +, not &.
  5. You don’t need to declare the end of the function; the } that matches with the opening { defines the end of the function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.