Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Javascript problem in tpl

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Cavi
Smarty n00b


Joined: 18 Sep 2013
Posts: 1

PostPosted: Wed Sep 18, 2013 10:13 am    Post subject: Javascript problem in tpl Reply with quote

Hello,

I use a classifieds script. This script uses tpl files. In one of the tpl files, I created a javascript function at the top between {literal} ... {/literal} tags. My function has too many lines (1700 so far). I used lots of document.getElementById( functions and lots of if controls like below :

I know I shouldn't use so many lines. But I am not good at coding and it worked nice until it reached 1700 lines. After 1700 lines (file size 180 kb), even I add one more line containing document.getElementById(.. it started not to work, doesn't display the form in the browser although there are no error messages or warnings. If I remove the line, it works again and displays the form. There is no error in the last line. Because I used hundreds of before.
What I am trying to do is to use a search form with nested select boxes. When a select box is clicked, I make the others hidden.

Does usage of document.getElementById so much cause this result? Or is there a limitation about the max lines or characters for a javascript function, or is there a limitation for these in a tpl or literal tags? Or should I change something in php.ini? This 1700 lines function is called in several select boxes in a search form.

I know it is very difficult to answer such a question but I am trying my chance in case the answer may be simple. Smile



{literal}
<script type="text/javascript">
function optionCheck(){
var option = document.getElementById("maincategories").value;
var option1 = document.getElementById("estate1").value;
var option2 = document.getElementById("estate2").value;
var option3 = document.getElementById("estate3").value;
var option4 = document.getElementById("estate4").value;
var option5 = document.getElementById("estate5").value;
var option6 = document.getElementById("estate6").value;
...

if(option == "6"){
document.getElementById("estate0").style.display = 'block';
document.getElementById("estate").style.display = 'block';
document.getElementById("cars0").style.display = 'none';

if ...

if ...


...

}

</script>{/literal}


<div class="containertable">
<form action="search.php" ondblclick="submit()" name="itemForm" id="itemForm" method="get">
<script language="javascript">
xajax_myFunction('{$reg_2_value}');
xajax_myFunction('{$reg_3_value}');
</script>
<input name="do_search" type="hidden" value="Search" />
<table cellspacing="3" border="0">
<tr>
<td><span style="text">{$smarty.const.LA_SEARCH}</span> </td>
<td><input id="searchword" name="searchword" size="25" class="txt" value="{$searchword}" /></td>
</tr>

<tr>
<td><span style="text">{$smarty.const.LA_S_CATEGORY}</span> </td>
<td>


<div style="float:left" id="main">
<select id="maincategories" name="catid_search" onchange="optionCheck()" class="regionselect" size="14">
<option value='0'>{$smarty.const.LA_ALL}</option>
<option value="6">Real Estate</option>
<option value="7">Cars</option>
<option value="8">Computers/option>
<option value="9">Electronics</option>
<option value="10">Internet</option>
<option value="11">Services</option>
<option value="15">Pets</option>
<option value="18">Goods</option>
<option value="19">Other</option>
</select>
...

</div>

Thank you for your help.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Sep 18, 2013 4:44 pm    Post subject: Reply with quote

I'm not shure into which sort of limit you are running.

You could try not to use {literal} but replace the javascript {,} by {ldelim},{rdelim} and see if it helps

See http://www.smarty.net/docs/en/language.function.ldelim.tpl
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP