...

View Full Version : Function Text Box



Tim Conner
07-12-2012, 01:17 AM
Would there be a way to have a text box that would do a function so if you typed in print("") it would give the pages value whaterver is in ""? Or something similar so I could build in some function that would use a part of it as a variable?

Old Pedant
07-12-2012, 01:27 AM
Do WHAT "function"? You mean, in your example, print something?

And what does "pages value" mean?

In general, the answer is "yes", but it really wouldn't be a good idea to just execute whatever is typed in. A user could type in something that would utterly mess up his display and then he would blame you.

Tim Conner
07-12-2012, 01:33 AM
Well this would just be for me what I mean is pagvalue would be a div and you could type in Print("") or some other commands and whatever is in"" the value of the page would be that.
I am trying to make some basic commands for something. Is there a way to parse it so if the first parts Print then get whatev is in "" and set pagevalue.value = ""?

Old Pedant
07-12-2012, 01:37 AM
Yes, but then why bother with print("")???



<input type="text" onchange="document.getElementById('pagevalue').innerHTML=this.value"/>

Old Pedant
07-12-2012, 01:38 AM
Maybe you need to give a real example?

Tim Conner
07-12-2012, 04:30 AM
Ok. Ill have 2-3 commands and one of them will print the other ones will do something else. So that why it needs to be a unique name. I know how to assighn text but I want to have a command. Its not going to be a command line but on a command line you type a keyword of function in and it executes.

Tim Conner
07-12-2012, 07:31 PM
I kinda figured it out here.



var str=document.getElementById("c").value;
var n=str.substr(0,5);
document.getElementById("page").innerHTML=n;

Tim Conner
07-12-2012, 07:38 PM
Ok this gets it correct but it leaves the closing ) in there any ideas?


var str=document.getElementById("c").value;
var n=str.substr(0,5);
//document.getElementById("page").innerHTML=n;
//var n=str.indexOf("(");


if(n=="Print"){
var b = str.indexOf("(");
var d = str.indexOf(")");
var q=str.substr(b+1,d-1);
document.getElementById("page").innerHTML=q;
}

Tim Conner
07-13-2012, 04:32 PM
How could I check if thers 2 characters and get the value. Becasue for one there coule be 1-2 characters? Would I check if the next character is a number or something

Old Pedant
07-13-2012, 08:57 PM
I just think you are working way way too hard.

But if you insist on doing it as you are:


var str=document.getElementById("c").value;
if ( str.toLowerCase().indexOf("print(") == 0 )
{
var q = str.substring( 6 );
q = q.substring( 0, q.length-1 );
document.getElementById("page").innerHTML=q;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum