Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: form - show a specific thing if another specific thing is entered

  1. #11
    Join Date
    Oct 2010
    Posts
    11
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I want the results text to be divs. I don't care if there is a table or not. If someone enters acceptable text, a set of div's could be called as the result. Then the same text would not have to be rewritten for each result that needs that text. In the stuff above if "goes with" "a" and "b" were text by themselves in 3 div's, those divs would be called if someone entered a or b.

    Everything below is working and finished, except I tried to do div's and now it won't work again.


    <html><head></head><body onload="document.notarealform.textfield.focus()">
    <script type="text/javascript">
    <!--
    document.write("<H>A heading</H><br /><br /><br />");
    function youentered(){
    var item = document.getElementById('item').value;
    document.getElementById('entereditem').innerHTML = item;
    document.getElementById('explanation').innerHTML = 'Your search entry: ';
    }
    function itemresults(){
    var itemField = document.getElementById('item');
    if (itemField.value == "a") {
    document.getElementById("show").innerHTML = "put a combination of div's something like this with the words written elsewhere so they don't have to be rewritten ---> <div 1, div 2, div 3">;
    } else if (itemField.value == "b") {
    document.getElementById("show").innerHTML = "put a combination of div's something like this with the words written elsewhere so they don't have to be rewritten ---> <div 2, div 1, div 4>";
    } else if (itemField.value == "") {
    document.getElementById("show").innerHTML = "Please enter some text.";
    } else {
    document.getElementById("show").innerHTML = "Not found.";
    }
    }
    //-->
    </script>
    <div id="1" bgcolor="f0faf5">some text for div 1</div>
    <div id="2" bgcolor="f0faf5">some text div 2</div>
    <div id="3" bgcolor="f0faf5">other text div 3</div>
    <div id="4" bgcolor="f0faf5">different text div 4</div>
    <p><br /><br />Enter some text.<p />
    <p><i id='explanation'>Your entry: </i><b id='entereditem'>none</b></p>
    <form method="post" name="notarealform">
    <input type='text' name="textfield" id='item' onkeyup='youentered()' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' onclick='itemresults()' value='Look It Up'/></form>
    </body></html>
    Last edited by asdfqwerty; 10-15-2010 at 08:23 AM. Reason: clarity (hopefully)

  2. #12
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You just need to change these lines. These lines find the element by the id then put the text inside of that element. ID's also cant be just numerical values you could make them "one" or "id_1".

    Code:
    document.getElementById("show").innerHTML
    So in your current example

    Code:
    document.getElementById("1").innerHTML
    I dont know what you mean by

    put a combination of div's something like this with the words written elsewhere so they don't have to be rewritten ---> <div 1, div 2, div 3
    Corrections to my coding/thoughts welcome.

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

    asdfqwerty (10-15-2010)

  4. #13
    Join Date
    Oct 2010
    Posts
    11
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Thanks blue walrus!!!

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
  •