Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm trying to understand why you need to pass the variable as a string and why you want to access <code>cont</code> via the <code>window</code> object. This does what it looks like you expected your code to do:</p> <pre><code>process = function (str) { alert(str); // This will alert 'once there lived a king named midas' } validate = function () { var cont = 'once there lived a king named midas'; process(cont); } validate(); </code></pre> <p>FYI: It is generally considered bad practice to declare global variables, especially in a case like this where you don't appear to need them. (I could'd we wrong, though; I'm not entirely sure what you're trying to accomplish)</p> <p><strong>Edit:</strong> I would suggest using some functions and passing some variables around rather than mucking around with <code>eval()</code>-esque variable references. For example, you could implement <code>makeParam</code> like so:</p> <pre><code>var cont = 'Boggis, Bunce, and Bean.', makeParam = function(str) { var param = '', i = 0, arg = str.split(','), l = arg.length; while (i &lt; l) { if (arg[i + 1].match(/\([a-zA-Z]+\)/)) { // No reason to capture param += [arg[1], cont].join('='); i += 2; } else if (arg[i].match(/\/[a-zA-Z]+\//)) { // No reason to capture param += [ arg[i], document.getElementById(arg[i]).value ].join('='); i += 1; } else { param += [arg[i], arg[i + 1]].join('='); i += 2; } param += (i + 1 === l) ? '' : '&amp;'; } return param; }; param = makeParam('command,insert,/title/,/keywords/,/description/,mode,[1],fckcontent, (cont)'); param === 'command=insert&amp;\ keywords=somekeywords&amp;\ description=somedescription&amp;\ mode=1&amp;\ fckcontent=Boggis, Bunce, and Bean.'; </code></pre> <p>But you'd probably want to pass <code>cont</code> into your <code>makeParam</code> function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload