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!

Problems with CF Javascript and DHTML

Status
Not open for further replies.

Puc

Programmer
Mar 12, 2001
10
GB
Here's the scenario, below is a JavaScript function and some Form HTML. What I need to do is pass the code labelled in red (or *** code I want to pass ***) to the innerHTML of the DIV (box1) so that it produces some dropdown date selector boxes.

The problem I am having depending on what I do is that:-
1] either the code executes within the JavaScript messing up the JavaScript (as the tag contains loads of HTML and JS) OR
2] I pass text to the DIV and it does not parse it as CF and does not display the drop down date boxes at all.

What should happen is when you click the "Show Date Dropdowns" link only the dropdowns should appear and when you click the "Show Textbox" link only the text box should appear.

Does anyone have any idea how I could achieve this? would hail you as the guru of all guru's if you could give me.

Puc. ( Code follows NB - custom tag CF_DROPDOWNS can be obtained from
*******************************************************
<script language =&quot;javascript>
function swapem(item)
{
var contents='';

if (item == 'date')
{
contents=' *** code I want to pass *** <cf_datedropdowns aname=&quot;adate&quot; startyear=&quot;2001&quot; endyear=&quot;2007&quot; formname=&quot;searchform&quot;>';
}
else
{
contents+='<span>contains</span><input name=&quot;searchtype&quot; type=&quot;radio&quot; value=&quot;contains&quot; <cfif isdefined(&quot;search&quot;)><cfif searchtype is &quot;contains&quot;>checked</cfif><cfelse>checked</cfif>>' ;
contents+='<span>&nbsp;&nbsp;starts with</span><input type=&quot;radio&quot; name=&quot;searchtype&quot; value=&quot;starts&quot; <cfif isdefined(&quot;search&quot;)><cfif searchtype is &quot;starts&quot;>checked</cfif></cfif>>';
contents+='<input type=&quot;text&quot; name=&quot;searchtext&quot; size=&quot;26&quot; value=&quot;<cfif isdefined('search')>#searchvalue#</cfif>&quot;></span>';
}

eval(&quot;document.all['box1'].innerHTML = contents&quot;);

}
</script>

---------------------------------------------------------

<a href=&quot;javascript:swapem('date')&quot;>Show Date Dropdowns</a>&nbsp;&nbsp;<a href=&quot;javascript:swapem('text')&quot;>Show Textbox</a><br><br>

<form action=&quot;htmltest2.cfm&quot; name=&quot;searchform&quot; method=&quot;post&quot;>
<table border=&quot;1&quot;>
<tr><td>This is the text above</td></tr>
<tr>
<td>
<div id=&quot;box1&quot;>
<!-- this is the DIV I want to put the contents into --->
</div>
</td>
</tr>
<tr><td>This is the text below</td></tr>
<tr><td><input type=&quot;Submit&quot; value=&quot;submit it&quot;></td></tr>
</table>
</form>
 
1 - do &quot;view source&quot; on the generated page - this will be easier to debug
2 - if you still can't locate what's not working, try to escape the &quot; --> replace them with \&quot; (in your jscript code)
3 - eval(&quot;document.all['box1'].innerHTML = contents&quot;); why do you need to eval this ??? this would work fine without eval
4 - remember that innerHTML is only ie4+ compliant
 
Thanks for your reply.

Already used the view source and I can get the exact text I need to be passed to the variable contents as text using DE etc, but then CF does not parse the code it jyst treats it as text.

As for the JS, sorry I should have left the eval out, I had a function in there previously to evaluate the DOM.
 
Put the evaluate CF function around the text CF will have to parse -> #evaluate(&quot;StringToEvaluate&quot;)#.
iza is right though, innerHTML only works in IE4+, remember that. Hope this helps...


<webguru>iqof188</webguru>
 
Hi I have tried to use the CF_Evaluate before passing it to the span but it evaluates the code and displays it on the page.

If I can inhibit this happening then I'd be laughing, but I can't seem to stop the javascript within the CF_datedropdowns tag being output to the screen.

I am aware of the IE4+ limitation on innerHTML, but you can actually write to a DIV in Netscape too, you just have to detaect the browser and use a Layers workaround.

IF you have any idea how I can get this problem sorted out I'd greatly appreciate it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top