• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JavaScript & HTML

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Complete novice here, but here's my question:

I am trying to code a simple 1 page example. I use a basic html page set up a couple of test boxes to get numerical data and then using the button element with onclik= to call a function(parm1,parm2) to display the answer.

Issue I have is that when I click on the button, the page clears and then gives the answer. I do not want the page to clear but rather have the answer appear on the next line.

Could someone explain why the page clears? Snipet below...

Sample snipet:

form
.
.
.
input type="button" name="button1" value="Click here for your answer" onclik="function(num1,num2)"
/form
.
.
.
script type="text/javascript"
function function(num1,num2)
{
.
.
.
return (answer);
}
.
.
.
[ October 25, 2005: Message edited by: Jon-Paul Ward ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough, and joke names and "handles" don't cut it either. You can change your display name
here.
Thanks!

Second, "Java" and "JavaScript" are two separate languages. Most of JavaRanch is about Java, not JavaScript, but we do have one JavaScript forum here. I will move your post there for you.
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like your button is acting as a reset, but there's nothing in the code you posted to support that... It's hard to diagnose the problem without seeing the complete code (hint, hint).
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
document.write is giving you problems. If you want your output to display below your form, try adding an empty DIV below it and using innerHTML to add your output text to the DIV.

Also...
You don't need a semi-colon inside of quotes in your script, only at the end of the line.
And getElementById only works reliably when you have an ID - your input elements only have names.
Script blocks should include this attribute: type="text/javascript"
And your DOCTYPE isn't valid.

Hope that helps!
g.
 
Jon-Paul Ward
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fuuny you should say that...was just reading the W3C HTML reference guide online, I it lead me to believe the solution layed with DIV element.

Thanks.
 
Jon-Paul Ward
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help. I see the solution right there in Mr. Pascarello's book on page 256. Funny thing is I read that earlier today and apparently didn't catch the rammifications of innerHTMl vs. Document.write .

Guess I have to reread that book again.
 
"To do good, you actually have to do something." -- Yvon Chouinard
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic