SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.write on submit form

    I have a simple piece of code:

    <script type="text/javascript" language="javascript">
    <!-- Begin
    document.write("Detection covers: <b>" + det + "</b>");
    // End -->
    </script>

    that I would like to execute only after a form submit calls a function that calculates the global variable ‘det’.

    <form method=post>
    <input type=text name=deg size=6 value=0 onFocus="select()">
    <input type=text name=res size=6 value=0 onFocus="select()">
    <input type=button value="calculate Resolution" onClick="resolution(this.form,'result')">
    </form>

    Can someone tell me the proper event definition that triggers the ‘document.write’.

    Werner

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onClick="resolution(this.form,'result');write_func()"

    ...but that doesn't get triggered when the user submits the form. To do that, put those funtions in an onsubmit event handler in the <form> tag.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    suggest that document.write is not best

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    </
    head>

    <
    body>
    <
    script type="text/javascript" language="javascript">
    <!-- 
    Begin

    function resolution(){
     
    document.getElementById('Result').innerHTML='<b>My Result</b>';
    }


    // End -->
    </script>

    that I would like to execute only after a form submit calls a function that calculates the global variable ‘det’.

    <form method=post>
    <input type=text name=deg size=6 value=0 onFocus="select()">
    <input type=text name=res size=6 value=0 onFocus="select()">
    <input type=button value="calculate Resolution" onClick="resolution(this.form,'result')">
    </form>
    <div id="Result"></div>
    Can someone tell me the proper event definition that triggers the ‘document.write’.

    </body>

    </html> 
    nore is my solution, but it's better

    ps
    it would be more normal to put the result into a text area or text field using .value=

  4. #4
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did try the text field which causes this ugly box around the results field. The idea is to naturally write computed result into a text line, like:

    ...detection, recognition, and identification at 'result1', 'result2', 'result3' respectively.

    that's when I started to think of using document.write.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use what's called the DOM to insert <div>'s into your page, or rewrite existing <div>'s. If you use document.write() after the page has loaded, you will overwrite the whole page. Here's a DOM tutorial:

    http://www.sitepoint.com/article/rough-guide-dom

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wkraemer
    I did try the text field which causes this ugly box around the results field.

    you can remove the border by ....style.border="0px' and cange the color by
    ....style.backgroundColor='#123456';

    font styles can be changed in the same way

    or use equ style class

  7. #7
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks vwphillips - I guess it's true: one learns something every day! I didn't know that one could change the border of the text field and have it work in IE and Firefox.

    Thanks
    Werner

  8. #8
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops - sorry - I didn't tell you that solved my original problem.

    Thanks again


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
  •