How do you write text to a specific location on the screen

Discussion in 'JavaScript' started by Imozeb, Jan 31, 2010.

  1. #1
    How do you write text to a specific location on the screen using javascript. I have made a html form and I am using javascript to validate it. I don't want to use a alert box because they are just so annoying, instead I want to write the errors to the screen above the fields that have the error. How do I do that? (using form and or div tags)

    Thanks.

    ~Imozeb
     
    Last edited: Jan 31, 2010
    Imozeb, Jan 31, 2010 IP
  2. aljosabre

    aljosabre Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use CSS. Something like this
    <html>
    <head>
    </head>
    <body>
    <div name="input" style="width:200px;height:200px;border-style:solid;border-color:#98bf21;border-width:5px;top:150px;position:absolute;left:200px;">
    <div style="position:relative;top:-32px;left:22px;">
    <b>Da da</b> Or ...<script>javascript:document.write("lol");</script>
    </div>
    </div>
    </body>
    </html>
    Code (markup):
     
    Last edited: Jan 31, 2010
    aljosabre, Jan 31, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I know how to do that but, what I don't know is how to refer to it through my javascript coding in the head tag.

    <head>
    <script text/javascript>
    document.write.... *
    </script>
    </head>
    <body>
    <input ....../>
    *(text needs to go here)
    </body>

    ~Imozeb :)
     
    Imozeb, Jan 31, 2010 IP
  4. rhewitt

    rhewitt Member

    Messages:
    113
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #4
    You could use jQuery to modify the CSS.
     
    rhewitt, Jan 31, 2010 IP
  5. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Can I do it using just javascript and form or div tags?
     
    Imozeb, Jan 31, 2010 IP
  6. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    assign a function to the onsubmit event of your form...
    
    <html><head>
    <script type="text/javascript">
    [B]document.getElementById("myForm").onsubmit = function() {[/B]
        document.getElementById("myDiv").innerHTML = "*** message here ***";
    [B]}[/B]
    </script>
    </head>
    <body>
    <div id="myDiv"></div>
    <form id="myForm" action="whatever.php" method="POST">
    >>> form code here <<<
    </form>
    </body>
    </html>
    
    Code (markup):
     
    Last edited: Feb 1, 2010
    camjohnson95, Feb 1, 2010 IP
  7. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks everyone :)
     
    Imozeb, Feb 1, 2010 IP
  8. nehakv

    nehakv Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    as you have asked an alternative way to display the text other than the alert mathod..
    you can use document.write();
     
    nehakv, Feb 4, 2010 IP