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

Thread: Sentence Generator

  1. #1
    Join Date
    Sep 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sentence Generator

    Greetings!

    I am looking for a very simple script that does not seem to exist..!

    It would be a series of drop-down boxes with text in them, and, after selecting a combination, a button which would gather all the text select by drop-downs and paste them into a field.

    I'll try to examplify:

    ~ is the next drop down box


    I ~ like ~ Dynamic Drive
    You ~ likes ~ DHTML
    He

    The sumbit button would paste either:

    I like Dynamic Drive
    You like Dynamic Drive
    He likes Dynamic Drive

    Into a text area, depending on what was selected.

    Has anyone seen this kind of script around?

    I will, of course combine this with the chained selects script and possibly a radio button to predefine what type of "sentence" would be loaded into the drop-downs.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <form action="" onsubmit="
      for(var i=0;this.elements['s' + i + '-1'];i++) {
        for(var j=0;this.elements['s' + i + '-' + j];i++) {
          this.elements['paragraph'].value += (j == 0 ? "" : " ") + this.elements['s' + i + '-' + j].value;
        }
        this.elements['paragraph'].value += '.\n';
      }
    ">
      <select name="s1-1">
        <option>I</option>
        <option>You</option>
        <option>He</option>
      </select>
      <select name="s1-2">
        <option>like</option>
        <option>likes</option>
      </select>
      <select name="s1-3">
        <option>Dynamic Drive</option>
        <option>DHTML</option>
        <option>cats</option>
      </select>
      <input type="submit">
      <textarea name="paragraph"></textarea>
    </form>
    Untested.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You're on the right path, but it doesn't seem to work..!

    Still scouring the web..

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Here we go... this one works.
    Code:
    <form action="" onsubmit="
      for(var i=1;this.elements['s' + i + '-1'];i++) {
        for(var j=1;this.elements['s' + i + '-' + j];j++) {
          this.elements['paragraph'].value += (j == 0 ? '' : ' ') + this.elements['s' + i + '-' + j].value;
        }
        this.elements['paragraph'].value += '.\n';
      }
      return false;
    ">
      <select name="s1-1">
        <option>I</option>
        <option>You</option>
        <option>He</option>
      </select>
      <select name="s1-2">
        <option>like</option>
        <option>likes</option>
      </select>
      <select name="s1-3">
        <option>Dynamic Drive</option>
        <option>DHTML</option>
        <option>cats</option>
      </select>
      <input type="submit">
      <textarea name="paragraph"></textarea>
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This.. doesn't work in IE but is fine in Opera.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ah -- try:
    Code:
    <form action="" onsubmit="
      for(var i=1;this.elements['s' + i + '-1'];i++) {
        for(var j=1;this.elements['s' + i + '-' + j];j++) {
          this.elements['paragraph'].value += (j == 1 ? '' : ' ') + (this.elements['s' + i + '-' + j].value || this.elements['s' + i + '-' + j].options[this.elements['s' + i + '-' + j].selectedIndex].innerHTML);
        }
        this.elements['paragraph'].value += '.\n';
      }
      return false;
    ">
      <select name="s1-1">
        <option value="">I</option>
        <option>You</option>
        <option>He</option>
      </select>
      <select name="s1-2">
        <option>like</option>
        <option>likes</option>
      </select>
      <select name="s1-3">
        <option>Dynamic Drive</option>
        <option>DHTML</option>
        <option>cats</option>
      </select>
      <input type="submit">
      <textarea name="paragraph"></textarea>
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Sep 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hah, what an insult to IE. Every time I dip into HTML/JS I sympathise with those that have to deal with this ridiculousness every day.
    Many thanks Twey, I will show you what I end up with after a bit of tweaking around..

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hah, what an insult to IE. Every time I dip into HTML/JS I sympathise with those that have to deal with this ridiculousness every day.
    Yeah, it is a bit daft writing a script for everything else, then having to do half of it again just for IE. I don't know if this is a case of that, though; I was relying on the browser, if finding no explicitly declared value for the option, using the option's text. Opera and Firefox, apparently, do this; IE doesn't. Whether it's correct behaviour or not, I don't know.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Sep 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I am looking to combine the above script this the chained selects script:
    http://www.dynamicdrive.com/dynamici...ects/index.htm

    Is this possible?

    I am guessing not because all the values for the chained selects are in a .js file.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, that should be no problem. Just keep the onsubmit the way it is, and so long as the Chained Selects doesn't require you to modify the names of the elements, there's no reason why not.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •