/    Sign up×
Community /Pin to ProfileBookmark

Can’t get input type="image" to work

Hello group, I can’t seem to get this work. It’s supposed to do this:

  • * user clicks on image and the X and Y coords are concatenated into a string as “X,Y,” etc.

  • * Then, the value is appended to the value in the text area.
  • So for example, if the user clicks in 3 different spots, the text area will have something simalar to:
    124,71,135,78,199,92,

    But what’s happening is that every time the user clicks, the form seems to ‘submit’ and the text area clears out. I know that the default event of the input image type is submit,
    but I can’t even get it to work using the image with a href tag and “OnClick”

    Please help.

    Thanks.

    Here’s the code:

    <html>
    <head>
    <title>Test</title>
    <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

    <script language=”JavaScript”>
    <!–
    // <!–

    function detect_mouse(field,x,y) {

    var fv = field.value;
    var test = fv + x + “,” + y + “,”;
    field.value = fv + x + “,” + y + “,”;

    }

    //–>
    </script>
    </head>

    <body bgcolor=”#CCCCCC” leftmargin=”0″ topmargin=”0″ marginwidth=”0″ marginheight=”0″>
    <form>
    <input type=”image” src=”image/C1.gif” width=”300″ height=”300″ onClick=”detect_mouse(this.form.TheTextArea,event.clientX,event.clientY);”>
    <br>

    <textarea name=”TheTextArea” cols=”50″ rows=”15″></textarea>
    </form>
    </body>
    </html>

    to post a comment
    JavaScript

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @gil_davisOct 29.2003 — [i]Originally posted by guysmily [/i]

    [B]<form>

    <input type="image" src="image/C1.gif" width="300" height="300" onClick="detect_mouse(this.form.TheTextArea,event.clientX,event.clientY);"><br>

    <textarea name="TheTextArea" cols="50" rows="15"></textarea>

    </form>[/B]
    [/QUOTE]

    Try this:
    &lt;form onSubmit="return false"&gt;
    &lt;input type="image" ... onClick="detect_mouse(this.form.TheTextArea,event.clientX,event.clientY);return false"&gt;
    Copy linkTweet thisAlerts:
    @guysmilyauthorOct 29.2003 — Gil,

    Wow, I feel stupid. Works like a charm!

    Thanks!

    Guy ?
    Copy linkTweet thisAlerts:
    @guysmilyauthorOct 29.2003 — One, question, what if I wanted to actually submit the form when the text area has the data I need?

    Is there a way to do that?
    Copy linkTweet thisAlerts:
    @gil_davisOct 29.2003 — &lt;input type="button" onclick="this.form.submit()" value="Submit"&gt;
    Believe it or not, the submit() function does not trigger the onSubmit event.
    Copy linkTweet thisAlerts:
    @guysmilyauthorOct 29.2003 — Thanks Gil.

    It works like a charm (again).

    Guy
    ×

    Success!

    Help @guysmily 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 5.7,
    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: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...