By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,640 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,640 IT Pros & Developers. It's quick & easy.

onClick

P: n/a
Ken
Does php work with onClick in an html input statement?

<HTML>
<input type="button" name="add_picture" value="Add another picture"
onClick="<?php picture_count(); ?>">

I want to call the function picture_count() when button labeled "Add another
picture" is clicked in HTML

I do not want to use submit in place of button since I do not want to submit
the form at this time.

With the above statement, I receive an error expected ";" and the function
is not called.

Thanks!
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ken wrote:
Does php work with onClick in an html input statement?

<HTML>
<input type="button" name="add_picture" value="Add another picture"
onClick="<?php picture_count(); ?>">

I want to call the function picture_count() when button labeled "Add another
picture" is clicked in HTML

I do not want to use submit in place of button since I do not want to submit
the form at this time.

With the above statement, I receive an error expected ";" and the function
is not called.

Thanks!


The function will not be called because:

A) PHP is serverside whereas the onclick event you are trying to catch
is client side.

B) the onclick attribute is (to my knowledge) expected to refer to a
javascript function/statement.

From what you've posted I can't tell exactly what is supposed to be
done when the user clicks the button (ie. what your function does) but
maybe you can consider using some javascript to reload the page and
update whatever your function was updating.

-Steve
Jul 17 '05 #2

P: n/a
Ken wrote:
Does php work with onClick in an html input statement?

<HTML>
<input type="button" name="add_picture" value="Add another picture"
onClick="<?php picture_count(); ?>">

I want to call the function picture_count() when button labeled "Add another
picture" is clicked in HTML

I do not want to use submit in place of button since I do not want to submit
the form at this time.

With the above statement, I receive an error expected ";" and the function
is not called.

Thanks!

You are mixing two different technologies together... PHP is server side
- The onClick event is client side... This means that your PHP code is
parsed/run BEFORE it gets to the user/client side.

If PHP is correctly configured on your server, then view the page where
you have the above code - My bet is that in the 'onClick' event, you
will NOT see <?php picture_count(); ?> but instead see the result of
picture_count() - And unless you manage to store the value/result of
picture_count somewhere on your server, then I'd guess that the value
will always be the same, no matter how many uploads you did.

Chances are, someone in comp.lang.javascript will (at least in part)
help you towards a solution...

laters
randelld
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.