Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Adding buttons to a sentence generator.

  1. #1
    Join Date
    Jul 2007
    Posts
    40
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Adding buttons to a sentence generator.

    So I've got this generator:

    http://tivaelydoc.110mb.com/test2.html

    But in the full version, I have 6 vars and 13 different tests.

    Is there a way to make a button or a html link to generate each one into a single text box?

    I know that I would have to define each test (ex: test1, test2, etc.) but what I don't know how to do is have a text box so that every time you click on one of the test buttons, a new generated string of words generates according to which button you clicked.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Do you have an example, I don't extremely get what you want. Do you want the buttons to be like: Ted, Bob, Bill, Stabbed, Hugged, Punch...?
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    tivaelydoc (12-30-2008)

  4. #3
    Join Date
    Jul 2007
    Posts
    40
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    The generator in the demo generates this:

    test = one[r(one.length)] + " " + two[r(two.length)] + " " + three[r(three.length)] + ".";

    one being var one etc.

    I've got 13 different versions of this and they generate all different sentences, such as two + three + six or whatever.

    Normally, the only way you can regenerate the text is by refreshing.

    So, what I want the buttons to be are all the different types of sentence generators.

    Let's say the first button just generates this (from the demo):

    test1 = one[r(one.length)] + ".";

    and the second one generates this:

    test2 = one[r(one.length)] + " " + two[r(two.length)] + " " + three[r(three.length)] + ".";

    Instead of having to refresh to regenerate, I want to make buttons called whatever that when clicked generate the adjacent string into a dynamic text box.

    I have a full example of what I'm talking about, but due to extreme explicit text, I don't think I can post it here. Although, if you're not easily offended, I can PM it to you.

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I've send you a PM.
    Last edited by Nile; 12-30-2008 at 04:10 AM.
    Jeremy | jfein.net

  6. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here, this should work:
    Code:
    <script type="text/javascript">
    var love = {
    names: ["Bill","Tom","Caroline","Macey"],
    actions: ["made cookies for","kissed","hugged","broke up with","got together with"],
    };
    
    var violence = {
    names: ["Bill","Tom","Caroline","Macey"],
    actions: ["stole from","punched","hit","stabbed"],
    };
    
    var social = {
    names: ["Bill","Tom","Caroline","Macey"],
    actions: ["chatted with","went out with","called","emailed"],
    };
    var randArr = function(arr){
      arr = arr.length;
      arr = Math.floor(Math.random()*arr);
      return arr;
    }
    var setRandom = function(type,el){
      var random;
      random = type.names[randArr(type.names)] +" "+ type.actions[randArr(type.actions)] +" "+ type.names[randArr(type.names)];
      el = document.getElementById(el).getElementsByTagName('input');
      for(i=0;i<el.length;++i){
        if(el[i].type == "text"){
          el[i].value = random
        }
      }
    }
    
    </script>
    
    <div id="inputHolder">
    <input type="button" onClick="setRandom(love,'inputHolder');" value="Love" />
    <input type="button" onClick="setRandom(violence,'inputHolder');" value="Violence" />
    <input type="button" onClick="setRandom(social,'inputHolder');" value="Social" />
    <br />
    <br />
    <input type="text" style="width:500px;height:50px;font-size:30px;font-family:arial;/>
    </div>
    I hope this works for you.
    Jeremy | jfein.net

  7. The Following User Says Thank You to Nile For This Useful Post:

    tivaelydoc (12-30-2008)

  8. #6
    Join Date
    Jul 2007
    Posts
    40
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Thanks, that worked exactly how I wanted it and then some!

    Since input type="text" is single line, I changed it to:
    PHP Code:
    <textarea id="text" name="text" style="width:100%;height:150px;font-size:2em;font-family:garamond;color:#990000;text-transform: uppercase;"></textarea
    so I can have multiple line.

    Then I changed the setRandom to:

    PHP Code:
    var setRandom5 = function(type,el){
      var 
    random;
      
    random type.subjects[randArr(type.subjects)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }

    But when I click on:

    PHP Code:
    <input type="button" onClick="setRandom5(violence,'inputHolder');" value="Violence" /> 
    nothing happens. How come?

  9. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Post all of your code please.
    Jeremy | jfein.net

  10. The Following User Says Thank You to Nile For This Useful Post:

    tivaelydoc (12-30-2008)

  11. #8
    Join Date
    Jul 2007
    Posts
    40
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    I haven't refined it, but I know it worked:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml"><head>

        
            <
    meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
            <
    title>Untitled Document</title>
            <
    style type="text/css">
    body {background-colorblack}
      </
    style>
        </
    head>
    <
    body spellcheck="false">
    <
    p valign="middle"><center>
    <
    script type="text/javascript">

    var 
    violence = {

    adverbs: ["Bill","Tom","Caroline","Macey"],

    adjectives: ["stole from","punched","hit","stabbed"],

    subjects: ["chatted with","went out with","called","emailed"],

    presentverbs: ["made cookies for","kissed","hugged","broke up with","got together with"],

    pastverbs: ["stole from","punched","hit","stabbed"],

    nouns: ["chatted with","went out with","called","emailed"],
    };

    var 
    randArr = function(arr){
      
    arr arr.length;
      
    arr Math.floor(Math.random()*arr);
      return 
    arr;
    }

    var 
    setRandom1 = function(type,el){
      var 
    random;
      
    random type.subjects[randArr(type.subjects)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom2 = function(type,el){
      var 
    random;
      
    random type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom3 = function(type,el){
      var 
    random;
      
    random type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom4 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom5 = function(type,el){
      var 
    random;
      
    random type.subjects[randArr(type.subjects)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom6 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom7 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom8 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.adjectives[randArr(type.adjectives)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom9 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.presentverbs[randArr(type.presentverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom10 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.adjectives[randArr(type.adjectives)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.presentverbs[randArr(type.presentverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom11 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.adjectives[randArr(type.adjectives)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.presentverbs[randArr(type.presentverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom12 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.adjectives[randArr(type.adjectives)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.presentverbs[randArr(type.presentverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    var 
    setRandom13 = function(type,el){
      var 
    random;
      
    random type.adverbs[randArr(type.adverbs)] +" "type.adjectives[randArr(type.adjectives)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.pastverbs[randArr(type.pastverbs)] +" "type.subjects[randArr(type.subjects)] +" "type.presentverbs[randArr(type.presentverbs)] +" "type.nouns[randArr(type.nouns)];
      
    el document.getElementById(el).getElementsByTagName('textarea');
      for(
    i=0;i<el.length;++i){
        if(
    el[i].type == "text"){
          
    el[i].value random
        
    }
      }
    }

    </script>

    <div id="inputHolder">
    <input type="button" onClick="setRandom1(violence,'inputHolder');" value="Love" />
    <input type="button" onClick="setRandom2(violence,'inputHolder');" value="Violence" />
    <input type="button" onClick="setRandom3(violence,'inputHolder');" value="Social" />
    <input type="button" onClick="setRandom4(violence,'inputHolder');" value="Love" />
    <input type="button" onClick="setRandom5(violence,'inputHolder');" value="Violence" />
    <input type="button" onClick="setRandom6(violence,'inputHolder');" value="Social" />
    <input type="button" onClick="setRandom7(violence,'inputHolder');" value="Love" />
    <input type="button" onClick="setRandom8(violence,'inputHolder');" value="Violence" />
    <input type="button" onClick="setRandom9(violence,'inputHolder');" value="Social" />
    <input type="button" onClick="setRandom10(violence,'inputHolder');" value="Love" />
    <input type="button" onClick="setRandom11(violence,'inputHolder');" value="Violence" />
    <input type="button" onClick="setRandom12(violence,'inputHolder');" value="Social" />
    <br />
    <br />
    <textarea id="text" name="text" style="background:black;width:100%;height:150px;font-size:2em;font-family:garamond;color:#990000;text-transform: uppercase;"></textarea>
    </div>
    </center></p>
        </body></html> 
    Here's the working version:

    http://tivaelydoc.110mb.com/java4.html
    Last edited by tivaelydoc; 12-30-2008 at 07:07 AM.

  12. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    It's something very messy now.
    I can make it cleaner, if you don't want me to, he's your code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><head>
    
        
            <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
            <title>Untitled Document</title>
            <style type="text/css">
    body {background-color: black}
      </style>
        </head>
    <body spellcheck="false">
    <p valign="middle"><center>
    <script type="text/javascript">
    
    var violence = {
    
    adverbs: ["Bill","Tom","Caroline","Macey"],
    
    adjectives: ["stole from","punched","hit","stabbed"],
    
    subjects: ["chatted with","went out with","called","emailed"],
    
    presentverbs: ["made cookies for","kissed","hugged","broke up with","got together with"],
    
    pastverbs: ["stole from","punched","hit","stabbed"],
    
    nouns: ["chatted with","went out with","called","emailed"],
    };
    
    var randArr = function(arr){
      arr = arr.length;
      arr = Math.floor(Math.random()*arr);
      return arr;
    }
    
    var setRandom1 = function(type,el){
      var random;
      random = type.subjects[randArr(type.subjects)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom2 = function(type,el){
      var random;
      random = type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom3 = function(type,el){
      var random;
      random = type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom4 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom5 = function(type,el){
      var random;
      random = type.subjects[randArr(type.subjects)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom6 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom7 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom8 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.adjectives[randArr(type.adjectives)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom9 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.presentverbs[randArr(type.presentverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom10 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.adjectives[randArr(type.adjectives)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.presentverbs[randArr(type.presentverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom11 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.adjectives[randArr(type.adjectives)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.presentverbs[randArr(type.presentverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom12 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.adjectives[randArr(type.adjectives)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.presentverbs[randArr(type.presentverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    var setRandom13 = function(type,el){
      var random;
      random = type.adverbs[randArr(type.adverbs)] +" "+ type.adjectives[randArr(type.adjectives)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.pastverbs[randArr(type.pastverbs)] +" "+ type.subjects[randArr(type.subjects)] +" "+ type.presentverbs[randArr(type.presentverbs)] +" "+ type.nouns[randArr(type.nouns)];
      el = document.getElementById(el).value = random;
    }
    
    </script>
    
    <div id="inputHolder">
    <input type="button" onClick="setRandom1(violence,'text');" value="Love" />
    <input type="button" onClick="setRandom2(violence,'text');" value="Violence" />
    <input type="button" onClick="setRandom3(violence,'text');" value="Social" />
    <input type="button" onClick="setRandom4(violence,'text');" value="Love" />
    <input type="button" onClick="setRandom5(violence,'text');" value="Violence" />
    <input type="button" onClick="setRandom6(violence,'text');" value="Social" />
    <input type="button" onClick="setRandom7(violence,'text');" value="Love" />
    <input type="button" onClick="setRandom8(violence,'text');" value="Violence" />
    <input type="button" onClick="setRandom9(violence,'text');" value="Social" />
    <input type="button" onClick="setRandom10(violence,'text');" value="Love" />
    <input type="button" onClick="setRandom11(violence,'text');" value="Violence" />
    <input type="button" onClick="setRandom12(violence,'text');" value="Social" />
    <br />
    <br />
    <textarea id="text" name="text" style="background:black;width:100%;height:150px;font-size:2em;font-family:garamond;color:#990000;text-transform: uppercase;"></textarea>
    </div>
    </center></p>
        </body></html>
    Jeremy | jfein.net

  13. The Following User Says Thank You to Nile For This Useful Post:

    tivaelydoc (12-30-2008)

  14. #10
    Join Date
    Jul 2007
    Posts
    40
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    If it's not too much trouble to ask, I wouldn't mind having it cleaned up. I lost my copy of dreamweaver, so I'm just going off the top of my head at the moment.

Bookmarks

Posting Permissions

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