wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes java Script Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "java Script Program" Watch "java Script Program" New topic
Author

java Script Program

Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
Hi

I have a code here:-----

FORM NAME="operations"

On Click event is "createwindow();addition(document.windowform)"

And another code to display the value of 2 additional numbers:----

function addition()
{
document.windowform.num3.value=
document.operations.num1.value+document.operations.num2.value
}

FORM NAME="windowform"

I am not able to display the addition of two numbers in a text box in another code.
Can you please help me out in this???

Thanks in advance
Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
Also I am getting the error messages while I am entering any HTML tags???
They say that the <> are not valid.
Could you tell me why am not able to post the HTML tags???
Liu Zhixiang
Ranch Hand

Joined: Aug 12, 2006
Posts: 32
You can replace "<" by "<" ,">" by ">".
And replace "onload" by "o n l o a d",etc..


I Think Therefore I Am
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9947
    
161

You can use this tool to escape those characters while posting the html code. The link to this tool is available in the HTML and JavaScript Forum home page


[My Blog] [JavaRanch Journal]
Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
Hi

I have a code here:-----

function createwindow()
{
MyWindow=window.open("OperationTwoNumbers/New.html","","toolbar=yes,location=yes,"+
"directories=yes,status=yes,menubar=yes,scrollbar=yes,resizable=yes,width=475,height=475"
}

FORM NAME="operations"
INPUT TYPE="button" NAME="windowform" VALUE=ADDITIONonclick="createwindow();addition(document.windowform)"

And another code to display the value of 2 additional numbers:----

function addition()
{
document.windowform.num3.value=
document.operations.num1.value+document.operations.num2.value
}

FORM NAME="windowform"

I am not able to display the addition of two numbers in a text box in another code.
Can you please help me out in this???

Thanks in advance
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9947
    
161

Try this out:

Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
Hi jaikiran,
I tried your above code but its not displaying any results in the 2nd window:
I have 2 codes here:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Arithmetic Operations </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
//this function creates a new window and loads the window with another HTML document
function createwindow()
{
MyWindow=window.open("OperationTwoNumbers/New.html","","toolbar=yes,location=yes,"+
"directories=yes,status=yes,menubar=yes,scrollbar=yes,resizable=yes,width=475,height=475"
}//closing the function createwindow()
function addition()
{
var a = document.operations.num1.value
var b = document.operations.num2.value
var c = Number(a) + Number(b)
document.windowform.num3.value = c
}
//End Hide Script-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFBCC" onload="operations.num1.focus()">
<H2 ALIGN="CENTER"><U>Perform the Arthmetic Operations on 2 numbers</U></H2>
<BR><BR>
<FORM NAME="operations">
<DIV ALIGN="CENTER">
<FONT SIZE=4 COLOR="RED">Enter the 1st Number:&nbsp;</FONT>
<INPUT TYPE="text" NAME="num1" SIZE=10>
<BR><BR>
<FONT SIZE=4 COLOR="RED">Enter the 2nd Number:</FONT>
<INPUT TYPE="text" NAME="num2" SIZE=10>
</DIV>
<BR><BR>
<DIV ALIGN="CENTER">
<INPUT TYPE="button" NAME="windowform" VALUE=ADDITION

onclick="createwindow();addition(document.windowform)">&nbsp;
</DIV>
<BR><BR>
<DIV ALIGN="CENTER">
<INPUT TYPE="reset" VALUE="Clear Fields" onclick="operations.num1.focus()">
</DIV>
</FORM>
</BODY>
</HTML>

and the other one for another window to display the result:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Result Page</TITLE>
</HEAD>
<BODY BGCOLOR="#FFC4FC">
<H2>The Result of the Operated Function:</H2>
<BR><BR>
<FORM NAME="windowform">
<DIV ALIGN="CENTER">
<FONT SIZE=4 COLOR="RED">Output Result:</FONT>
<INPUT TYPE="text" NAME="num3" READONLY><BR><BR>
</DIV>
</FORM>
</BODY>
</HTML>
Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
Hi Can anyone help me out in this problem???

Thanks in advance!!!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9947
    
161

I tried your above code but its not displaying any results in the 2nd window


The code that i posted wasnt meant to display the result in the new window. It's meant to display the result in the current window
Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
hI jaikiran,
So can you tell me where I am missing in the code and why it is not displaying th eresult in the new Window...
Appreciated!!!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9947
    
161

Try this out:



Note that your New.html which opens in a new window should have the form with name windowform and should contain the textbox with id num3
Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
HEY THANKS JAIKIRAN!!!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Brijesh ,

If I were the poster here during your timezone, I would not have answered the question since you demanded it a little bit. Remember we are volunteers here so if you do not get a response in an hour, do not post "I AM WAITING" type of messages.

Also your code above is going to fail on a slow connection since the window will not exist when you write to it.

Eric
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9947
    
161

Also your code above is going to fail on a slow connection since the window will not exist when you write to it.


Thanks for pointing the out, Eric
I am a novice to Javascript and hence failed to think about that. Just out of curiosity, i tried out a alternate approach as below:

FirstPage.html:



Output.html:



In this case, i am delegating the responsibility of displaying the result, to the window that is getting opened(Output.html). In the onload method of the Output.html i am calculating the sum and displaying it. Do you think this is an appropriate solution?

Also in this case, what if the parent window was closed even before the onload event on the child window was called? Is this still going to work?

Thanks for your time.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: java Script Program
 
Similar Threads
Reading parameter from JSP page
Unable to set the value Inside the TextFiled using java script
how to get a variable and print in same page
bean:write tag - query
Help in Oracle!