Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    gettin results in alert box and on new page

    currently working on a project and I cant figure the right coding to get my results to pop up in a new page, same window AND an alert box. I got the alert box part down perfectly but cannot figure out how to get my results. Even if i can figure out how to get them on the same page in their designated field, I can probably figure the rest out, the coding i have so far looks like this: ( i cant figure out how to make it look cool in a diff. window... sorry)

    <HTML>
    <HEAD>
    <b>
    Here is a pay slip generator that will determine your net annual salary.
    <br>
    Simply type in your first and last name along with gross salary and hit calculate.
    <br>
    Doing this will let you know how much you will end up paying in both Federal and State taxes.
    </b>
    <form action="" method="post">
    <p> Enter your First Name:
    <input name="num1" type="text" id="num1" size="10" maxlength="10">
    </p>
    <p> Enter your Last Name:
    <input name="num2" type="text" id="num2" size="10" maxlength="10">
    </p>
    <p> Enter your gross salary:
    <input name="num3" type="#" id="num3" size="10" maxlength="10">
    </p>
    Click this button to calulate your annual net pay!
    <script type="text/javascript">
    function calculate()
    {
    var fName = document.getElementById('num1').value;
    var lname = document.getElementById('num2').value;
    var sal = Number(document.getElementById('num3').value);
    alert('Hello '+ fName + ' '+ lname + ', you would pay $'+ sal * .2 + ' in Federal taxes and $'+ sal * .1 + ' in State taxes, leaving you $'+ sal * .7 + ' to take home annually!'); //for testing
    }
    </script>
    <input type="button" onclick="calculate()" value="Generate Pay Slip" />
    <input type="button" value="Reset Form" onClick="this.form.reset()" />
    <p>Total federal taxes:
    <input name="num4" type="#" id="num4" size="10" maxlength="10" value= N/A>
    </p>
    <p>Total State taxes:
    <input name="num5" type="#" id="num5" size="10" maxlength="10" value= N/A>
    </p>
    <p>Net annual salary:
    <input name="num6" type="#" id="num6" size="10" maxlength="10" value= N/A>
    <script type="text/javascript">
    function show_results
    {
    var ftax = document.getElementbyId('num4').value;
    var stax = document.getElementbyId('num5').value;
    var npay = document.getElementbyId('num6').value;
    }
    </TEXTAREA>
    </FORM>
    </body>
    </html>
    </script>

    Any clues would be very helpful

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Homework?

    </TEXTAREA>
    </FORM>
    </body>
    </html>
    </script>

    Not valid code! What textarea?

    To pass data to another page you will have to use a query string or a cookie.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Homework?

    </TEXTAREA>
    </FORM>
    </body>
    </html>
    </script>

    Not valid code! What textarea?

    To pass data to another page you will have to use a query string or a cookie.
    considered a project but homework does it justice, i tried typing it in a bunch of different ways but ultimately couldnt figure it out, my assumption was trying to assign each text box i created that had fed tax, s tax, and net pay a variable name and then having the results compute in there.. the problem was whenever i kept trying that i would cause the alert box to either not show up or the results wouldnt display.

  • #4
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by I2izzo View Post
    currently working on a project and I cant figure the right coding to get my results to pop up in a new page....
    To open a new page you can use window.open(). There are a range of parameters you can set to control the new window. Let google be your friend

    Code:
    var newWin = window.open();  //opens a blank window
    To then write content to the newly opened page

    Code:
    newWin.document.write('whatever content you want on the new page');

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by webdev1958 View Post
    To open a new page you can use window.open(). There are a range of parameters you can set to control the new window. Let google be your friend

    Code:
    var newWin = window.open();  //opens a blank window
    To then write content to the newly opened page

    Code:
    newWin.document.write('whatever content you want on the new page');
    Not a very good solution unless the content of the new page is extremely limited. You would have to use document.write() to generate the whole of the page content. document.write() encourages bad structure, in which script and markup are intermingled. And probably you will soon get tangled up in single/double quotes problems. If a script is written out then the closing tag must be split:-

    document.write('<script type="text/javascript">alert(1 + 2); </scr' + 'ipt>');

    Remember that after the write is complete, you need to close the document by using the document.close() method.
    Last edited by Philip M; 03-17-2012 at 09:40 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Reply is in red.

    Quote Originally Posted by Philip M View Post
    Not a very good solution unless the content of the new page is extremely limited.

    A. In this case it's only a quote being written to the new page, so it wouldn't be an issue for me.

    Last edited by webdev1958; 03-17-2012 at 10:32 AM.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    As I said, "Remember that after the write is complete, you need to close the document by using the document.close() method. "

    Code:
    <script type="text/javascript">
    window.onload = function () {
      document.open();
      document.write('<p>What ever you want to write<\/p>');
      document.write('<p>More stuff you want to write<\/p>');
      document.close();
    };
    </script>

    It is quite true that most browsers will automatically close the stream for you. The notable exception here is the Mozilla/Firefox family of browsers, that will continue to show a loading graphic until you close the stream. Some other browsers may fail to render part or all of the content. Just to be safe, make sure you always close the stream. I would have thought that anyone claiming any kind of professionalism would understand that.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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