/    Sign up×
Community /Pin to ProfileBookmark

Button tag refreshes my page on click

Hey,

I have this kind of a button on my page:

[CODE]<button id=”buttonM” onMouseDown=”myFunction()”><img src=”multi.png”></button>[/CODE]

So every time when I press that button, the page gets refreshed.
Here’s the code of myFunction() :

[code]
myFunction()
{
alert(“What’s up?”);
}
[/code]

The reason, that I use the <button> -tag instead of <input type=”button”> is that I use images in the button. How can I disable the refresh?

  • Ceox
  • to post a comment
    HTML

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @dtm32236Mar 05.2008 — why not do this?

    [code=html]<a onclick="myFunction();"><img src="multi.png"></a>[/code]
    Copy linkTweet thisAlerts:
    @beastiewebdevMar 05.2008 — I just tried what you are having problems with - worked ok for me...

    I did have to add the word "function" before "myFunction" in your javascript.

    So you have a button, when you click it you have your popup, close your popup and you are back to the page... What problem are you having?


    [CODE]
    <html>
    <head>
    <script type="text/javascript">
    function myFunction()
    {
    alert("What's up?");
    }
    </script>
    </head>
    <body>
    <button id="buttonM" onMouseDown="myFunction()"><img src="multi.gif"></button>
    </body>
    </html>[/CODE]
    Copy linkTweet thisAlerts:
    @CeoxauthorMar 05.2008 — Yes, I have the function word too, just forgot it there.

    After I closed the alert- window the page reloads.
    Copy linkTweet thisAlerts:
    @beastiewebdevMar 05.2008 — I cant replicate the problem....

    I added an alert into my body;

    [CODE]<script type="text/javascript">
    alert("page loaded")
    </script>[/CODE]


    I never got the page loaded alert once i closed the box...

    Can you post more of your code so we can try identify the problem?
    Copy linkTweet thisAlerts:
    @CeoxauthorMar 05.2008 — Okey, so here's the actual code:
    <i>
    </i>**calc.php**
    *some html*
    &lt;script type="text/javascript"&gt;
    function Write(Number)
    {

    <i> </i>if(Number == "c")
    <i> </i>{
    <i> </i>document.calculator.hand.value = "";
    <i> </i>document.calculator.calculation.value = "";
    <i> </i>}
    <i> </i> document.calculator.hand.value = document.calculator.hand.value + Number;
    <i> </i> document.calculator.calculation.value = document.calculator.calculation.value + Number;

    replaceVars();
    makeResult();
    setWhole();
    }


    &lt;/script&gt;
    &lt;form name="calculator"&gt;
    &lt;input type="text" maxlength="30" size="20" name="calculation"&gt;&lt;br&gt;
    &lt;input type="text" name="hand" size="20" readonly="readonly"&gt;
    &lt;/form&gt;

    &lt;button id="buttonM" onMouseDown="Write('*')"&gt;&lt;img src="multi.png"&gt;&lt;/button&gt;
    *some html*


    This is for a javascript calculator, that I'm developing, and those other functions do not reload the page in any way. (replaceVars, makeResult and setWhole).
    ×

    Success!

    Help @Ceox spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...