• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

java Script Program

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can replace "<" by "<" ,">" by ">".
And replace "onload" by "o n l o a d",etc..
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this out:

 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Can anyone help me out in this problem???

Thanks in advance!!!
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HEY THANKS JAIKIRAN!!!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic