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 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function Text Box

    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?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    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.
    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
    New Coder
    Join Date
    Jul 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 = ""?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Yes, but then why bother with print("")???

    Code:
    <input type="text" onchange="document.getElementById('pagevalue').innerHTML=this.value"/>
    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
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Maybe you need to give a real example?
    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.

  • #6
    New Coder
    Join Date
    Jul 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Jul 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I kinda figured it out here.
    Code:
    var str=document.getElementById("c").value;
    var n=str.substr(0,5);
    document.getElementById("page").innerHTML=n;

  • #8
    New Coder
    Join Date
    Jul 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok this gets it correct but it leaves the closing ) in there any ideas?
    Code:
    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;
    }

  • #9
    New Coder
    Join Date
    Jul 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    I just think you are working way way too hard.

    But if you insist on doing it as you are:
    Code:
    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;
    }
    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.


  •  

    Posting Permissions

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