...

View Full Version : gettin results in alert box and on new page



I2izzo
03-16-2012, 08:56 PM
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

Philip M
03-16-2012, 09:00 PM
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.

I2izzo
03-16-2012, 09:07 PM
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.

webdev1958
03-17-2012, 02:26 AM
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 :)


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


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

Philip M
03-17-2012, 09:10 AM
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 :)


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


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.

webdev1958
03-17-2012, 09:45 AM
Reply is in red.


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.

Philip M
03-17-2012, 10:06 AM
As I said, "Remember that after the write is complete, you need to close the document by using the document.close() method. "


<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. :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum