www.webdeveloper.com
Results 1 to 7 of 7

Thread: Dynamic content

  1. #1
    Join Date
    Jan 2014
    Posts
    3

    Dynamic content

    Hello everyone.
    I would like to create an input field which sends the text to the database and then automaticly updates a certain div content.
    The db part I know how to do, but I don't the updating part:

    -----------------------------------------------------------
    Enter text (on click, send text to db and change div1 text)
    -----------------------------------------------------------

    -----------------------------------------------------------
    div1 text
    -----------------------------------------------------------

    So how can I do that?
    Thanks.

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    238
    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
        <title>Untitled</title>
        <script type='text/javascript'>
            window.onload = function() {document.getElementById("div1").innerHTML="Hello world!!!"}
        </script>
    </head>
    <body>
        <div id="div1"></div>
    </body>
    </html>

  3. #3
    Join Date
    Jan 2014
    Posts
    3
    Thanks for the quick replay.
    I'm looking for something like:

    Code:
    <form name="input" action="html_form_action.asp" method="get">
    	<input type="text" id="t1" name="t1" placeholder="Say something">
    	<input type="submit" value="Submit" onclick="document.getElementById("div1").innerHTML="t1"">
    </form>
    <div id="div1"></div>
    The innerHTML will change the div1 value to the t1(text input) value.
    But I don't really know how to grab that input value.

  4. #4
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    238
    To get hold of t1 element's value you need something like this:

    Code:
    document.getElementById('t1').value;
    But when the form gets submited probably the best way (if not the only one) is to call a function which will get hold of t1 value and then update the div1.

  5. #5
    Join Date
    Jan 2014
    Posts
    3
    Thanks!!

  6. #6
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    238
    You're welcome!

  7. #7
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    238
    Ok, this would also work...

    Code:
    <div id="div1"></div>
    <form name="input" action="html_form_action.asp" method="get">
    	<input type="text" id="t1" name="t1" placeholder="Say something">
    	<input type="submit" value="Submit" onclick="document.getElementById("div1").innerHTML=t1.value>
    </form>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles