onclick()- simple javascript help

Discussion in 'JavaScript' started by hanushh, Nov 26, 2008.

  1. #1
    Hello. I am new to javascripting. I am building a simple application. What I need is when the javascript function is called, I dont need the page to be reloaded and theoutput to be displayed in a new page. the output must be displayed write below input tag. When I tried the below I got a new page with no other styles and html except "Hello World".

    
    		<input type="button" class="green" onclick="fuct()" value="Generate My Scrap" />
    HTML:
    function funct()
    {
    document.write("Hello World");
    
    }
    Code (markup):

     
    hanushh, Nov 26, 2008 IP
  2. irunbackwards

    irunbackwards Peon

    Messages:
    791
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could do something like this ...

    <input type="button" class="green" onClick="myFunction()" value="Generate My Scrap" />
    <div id="contentSwap" name="contentSwap"></div>
    Code (markup):
    function myFunction() {
    	document.getElementById('contentSwap').innerHTML='Hello World';
    }
    Code (markup):
     
    irunbackwards, Nov 26, 2008 IP
  3. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #3
    or try jquery or Ajax thats what most people use nowadays
     
    vic_msn, Nov 28, 2008 IP
  4. adamhk

    adamhk Member

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    This could work if you dont use XHTML strict.
     
    adamhk, Nov 29, 2008 IP