www.webdeveloper.com
Results 1 to 3 of 3

Thread: Poll with image input type not working

  1. #1
    Join Date
    Mar 2013
    Posts
    2

    Poll with image input type not working

    Hello

    I am having a problem making a php+ajax poll work. The code can be found here: http://www.w3schools.com/php/php_ajax_poll.asp

    Now instead of
    Code:
    <input type="radio" name="vote" value="0" onclick="getVote(this.value)">
    I've changed it to
    Code:
    <input type="image" src="image.png" name="vote" value="0" onclick="getVote(this.value)">
    in hoping that when I click on the image, the same result would be produced like when its a radio button.

    But its not working. By that I mean when I click the image, nothing happens, and the values in poll_result.txt doesn't change either. As for the URL I get http://localhost:8080/?vote.x=181&vote.y=90&vote=0

    Any help would be much appreciated.

    Cheers

  2. #2
    Join Date
    Mar 2011
    Posts
    1,138
    <input type="image"> is treated the same as <input type="submit">. So when you click on it, the JavaScript is being executed, but the <form> is "submitted" immediately thereafter. That means the browser will (essentially) reload the page and it looks like no changes have occurred. Try using a plain <img> tag instead. You won't be able to use 'getVote(this.value)', since <img> tags don't have a 'value' attribute. But you should be able to find a workaround easily enough.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Mar 2013
    Posts
    2
    Quote Originally Posted by rtrethewey View Post
    <input type="image"> is treated the same as <input type="submit">. So when you click on it, the JavaScript is being executed, but the <form> is "submitted" immediately thereafter. That means the browser will (essentially) reload the page and it looks like no changes have occurred. Try using a plain <img> tag instead. You won't be able to use 'getVote(this.value)', since <img> tags don't have a 'value' attribute. But you should be able to find a workaround easily enough.
    Thank you it solved my problem. I didn't even think about using the img tag :P

    Cheers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles