Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Sim
    Sim is offline
    New Coder
    Join Date
    Feb 2009
    Posts
    82
    Thanks
    1
    Thanked 1 Time in 1 Post

    Max characters that can be passed threw a Javascript function?

    Is there a maximum amount of characters that can be passed threw a javascript function paramater?

    ex: display(var1, var2)

    say var1 is 2 characters, var2 is 323432432 characters? theoritly speaking.
    Online RPG Creator - Create Your Own Online RPG with no programming knoweldge

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    That question really threw me. Until I realized you meant "through".

    Anyway, I think you asked the wrong question.

    Reason: When you pass a string as an argument to a function, you are really only passing a *REFERENCE* to the string. And a *REFERENCE* will surely be represented as a memory pointer of some kind, which means it will likely be a 4-byte or 8-byte pointer (or possible integer, as an index into heap space, but I tend to doubt that implentation would be used).

    So the real question you are asking: What is the maximum length of a *STRING* in JavaScript?

    The answer is surely both browser dependent and computer dependent.

    Computer dependent because of course a string can't be longer than available memory on a given computer.

    Browser dependent because it depends on how strings are implemented in a given browser.

    Likely the theoretical maximum in most JavaScript implementations is 4 gigabytes or 2 gigacharacters, depending on implementation. Remember that all JavaScript strings are Unicode strings, so that normally means 2 bytes per character. (At least one source--at Google--says, though, that the maximum is about 512MB--or 256 megacharacters--for Chrome.)

    But that's all kind of moot: The real limit will almost surely depend on how much space the operating system has allocated for the current browser. After all, the browser has to share memory space with all the other programs executing in your computer. Can the sum of the memory sizes exceed the amount of RAM in your computer? Sure. Heard of "virtual memory", haven't you? But in general the OS will want to try to make sure that all *active* applications are running in real memory.

    In practice, if you can manage to make a string too large for a given browser, then your code isn't going to run very well, no matter what. So why are you trying to do this?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Sim
    Sim is offline
    New Coder
    Join Date
    Feb 2009
    Posts
    82
    Thanks
    1
    Thanked 1 Time in 1 Post
    My html: I am using smarty templating:

    PHP Code:
                            <td>
                                <
    strong>Triggers:</strong>
                                <
    a href="javascript:;" onclick="AddTrigger('{$template_path}', '{section name=mysec loop=$stats_loop}{$stats_loop[mysec].id}:{$stats_loop[mysec].name}:{/section}','{section name=mysec loop=$items_loop}{$items_loop[mysec].id}:{$items_loop[mysec].name}:{/section}','{section name=mysec loop=$quests_loop}{$quests_loop[mysec].id}:{$quests_loop[mysec].name}:{/section}','{section name=mysec loop=$npcs_loop}{$npcs_loop[mysec].id}:{$npcs_loop[mysec].name}:{/section}','{section name=mysec loop=$images_loop}{$images_loop[mysec].id}:{$images_loop[mysec].name}:{/section}','{section name=mysec loop=$sounds_loop}{$sounds_loop[mysec].id}:{$sounds_loop[mysec].name}:{/section}','{section name=mysec loop=$zones_loop}{$zones_loop[mysec].id}:{$zones_loop[mysec].name}:{/section}');">Add Another Trigger</a>
                            </
    td
    I am sending my combo box value's through the function. then my javascript. ITS NOT FINISHED YET.

    Code:
    function AddTrigger(path, stat, item, quest, npc, image, sound, zone) {
    
      var stats = stat.split(":");
      
      var items = item.split(":");
      
      var quests = quest.split(":");
      
      var npcs = npc.split(":");
      
      var images = image.split(":");
      
      var sounds = sound.split(":");
      
      var zones = zone.split(":");
    
      var stat_str = '';
      var item_str = '';
      var quest_str = '';
      var npc_str = '';
      var image_str = '';
      var sound_str = '';
      var zone_str = '';
      
      for(var i=0; i<stats.length; i=i+2)
      {
    	stat_str = stat_str + '<option value="' + stats[i] + '">' + stats[i + 1] + '</option>';
      }
     
      for(var i=0; i<items.length; i=i+2)
      {
    	item_str = item_str + '<option value="' + items[i] + '">' + items[i + 1] + '</option>';
      }
     
      for(var i=0; i<quests.length; i=i+2)
      {
    	quest_str = quest_str + '<option value="' + quests[i] + '">' + quests[i + 1] + '</option>';
      }
     
      for(var i=0; i<npcs.length; i=i+2)
      {
    	npc_str = npc_str + '<option value="' + npcs[i] + '">' + npcs[i + 1] + '</option>';
      }
     
      for(var i=0; i<images.length; i=i+2)
      {
    	image_str = image_str + '<option value="' + images[i] + '">' + images[i + 1] + '</option>';
      }
     
      for(var i=0; i<sounds.length; i=i+2)
      {
    	sound_str = sound_str + '<option value="' + sounds[i] + '">' + sounds[i + 1] + '</option>';
      }
     
      for(var i=0; i<zones.length; i=i+2)
      {
    	zone_str = zone_str + '<option value="' + zones[i] + '">' + zones[i + 1] + '</option>';
      }
     
    
      var ni = document.getElementById('div_new_cond');
    
      var numi = document.getElementById('theValue');
    
      var num = (document.getElementById('theValue').value -1)+ 2;
     
      numi.value = num;
    
      var newdiv = document.createElement('div');
    
      var divIdName = 'my'+num+'Div';
    
      newdiv.setAttribute('id',divIdName);
     
      newdiv.innerHTML = '<tr><td><img src="' + path + '/default/images/minus.jpeg"> On <select id="selectOption" name="selectOption"><option value="attempt">Attempt</option><option value="if_attempted">If Attempted</option><option value="fail">Fail</option><option value="success">Success</option></select><select name="selectCondition" id="selectCondition" onchange="showCondition()"><optgroup label="Stats"><option value="decrease_stat">Decrease Stat</option><option value="increase_stat">Increase Stat</option><option value="set_stat">Set Stat</option><option value="require_stat">Require Stat</option></optgroup><optgroup label="Tasks"><option value="hide_task">Hide Task</option><option value="show_task">Show Task</option>						<option value="lock_task">Lock Task</option><option value="unlock_task">Unlock Task</option></optgroup><optgroup label="Items"><option value="add_item">Add Item</option><option value="remove_item">Remove Item</option></optgroup><optgroup label="Battling"><option value="attack_player">Attack Player</option><option value="force_battle">Force Battle</option></optgroup><optgroup label="Displays"><option value="display_image">Display Image</option><option value="display_text">Display Text</option><option value="display_sound">Play Sound</option><option value="display_cut_scene">Display Cut Scene</option></optgroup><option value="display_npc">Display NPC</option><option value="move_npc">Move NPC</option><option value="unlock_npc">Unlock NPC</option><option value="lock_npc">Lock NPC</option></optgroup><optgroup label="Quest"><option value="start_quest">Start Quest</option><option value="unlock_quest">Unlock Quest</option><option value="hide_quest">Hide Quest</option><option value="end_quest">End Quest</option><optgroup label="Travel"><option value="teleport">Teleport</option></optgroup></select><div id="valuez"><div id="div_stats"><select id="selectStat" name="selectStat">' + stat_str + '</select>By <input name="textStatMin" type="text" id="textStatMin"> - <input name="textStatMax" type="text" id="textStatMax"></div><div id="div_items"><select id="selectItem" name="selectItem">' + item_str + '</select></div><div id="div_quests"><select id="selectQuest" name="selectQuest">' + quest_str + '</select></div><div id="div_npcs"><select id="selectNPC" name="selectNPC">' + npc_str + '</select></div><div id="div_images"><select id="selectImage" name="selectImage">' + image_str + '</select></div><div id="div_sounds"><select id="selectSound" name="selectSound">' + sound_str + '</select></div><div id="div_zones"><select id="selectZone" name="selectZone">' + zone_str  + '</select></div>  <div id="div_texts"><input name="textText" type="text" id="textText"></div>  </div></td></tr>';
    
      ni.appendChild(newdiv);
    
    }
    Online RPG Creator - Create Your Own Online RPG with no programming knoweldge

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    That newdiv.innerHTML is a really bad way to create the contents of that div.

    Ugly to use innerHTML with that much crap.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Sim
    Sim is offline
    New Coder
    Join Date
    Feb 2009
    Posts
    82
    Thanks
    1
    Thanked 1 Time in 1 Post
    What would be a better way to approach this?
    Online RPG Creator - Create Your Own Online RPG with no programming knoweldge

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    Quote Originally Posted by Old Pedant View Post

    Likely the theoretical maximum in most JavaScript implementations is 4 gigabytes or 2 gigacharacters, depending on implementation. Remember that all JavaScript strings are Unicode strings, so that normally means 2 bytes per character. (At least one source--at Google--says, though, that the maximum is about 512MB--or 256 megacharacters--for Chrome.)

    But that's all kind of moot: The real limit will almost surely depend on how much space the operating system has allocated for the current browser. After all, the browser has to share memory space with all the other programs executing in your computer.
    V8 has a 1gb/instance default pool size, no matter how much RAM the device has. you can use command-line switches to alter that, but you shouldn't be needing that much ram, considering the async storage options available these days.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Sim View Post
    Is there a maximum amount of characters that can be passed threw a javascript function paramater?

    ex: display(var1, var2)

    say var1 is 2 characters, var2 is 323432432 characters? theoritly speaking.
    Why does it matter? Surely no real-world example approaches those limits.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •