/    Sign up×
Community /Pin to ProfileBookmark

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: [URL=”http://www.w3schools.com/php/php_ajax_poll.asp”]http://www.w3schools.com/php/php_ajax_poll.asp[/URL]

Now instead of

[CODE]<input type=”radio” name=”vote” value=”0″ onclick=”getVote(this.value)”>[/CODE]

I’ve changed it to

[CODE]<input type=”image” src=”image.png” name=”vote” value=”0″ onclick=”getVote(this.value)”>[/CODE]

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 [url]http://localhost:8080/[/url][B]?vote.x=181&vote.y=90&vote=0[/B]

Any help would be much appreciated.

Cheers

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rtretheweyMar 24.2013 — <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.
Copy linkTweet thisAlerts:
@iknowyouauthorMar 25.2013 — <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.[/QUOTE]

Thank you it solved my problem. I didn't even think about using the img tag ?

Cheers
×

Success!

Help @iknowyou 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.17,
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,
)...