submitting form through javascript

B

Bob Smith

Hi all
I have a page which contains a form.
I want a customized button with an image for the submit button, and when the
submit button has been clicked send the form to the perl script.
Now the form is no problem but the button is, so the question is how do I
create a custom button and how do I submit the form with javascript when the
button is clicked?
many thank's for any hint and help
B
 
F

Fred Serry

Bob Smith said:
Hi all
I have a page which contains a form.
I want a customized button with an image for the submit button, and when the
submit button has been clicked send the form to the perl script.
Now the form is no problem but the button is, so the question is how do I
create a custom button and how do I submit the form with javascript when the
button is clicked?
many thank's for any hint and help
B

Hi

Why use javascript? <input type=image> does what you want

http://msdn.microsoft.com/library/d...uthor/dhtml/reference/objects/input_image.asp

Fred
 
B

Bob Smith

Hi

Why use javascript? <input type=image> does what you want
thank's
but it doesn't work as expected,
the form is not submitted
( browser netscape 4.7x)
any help much appreciated.
B
 
S

Sean Jorden

thank's
but it doesn't work as expected,
the form is not submitted
( browser netscape 4.7x)
any help much appreciated.
B

dude, seriously. The following two are equivalent:

<input type="image" src="some_image.gif" name="submit" />
<input type="submit" name="submit.x" />

they will both submit the form.. I would hazard to guess this even works on
Netscape 2.0. Of course .. you need an actual GIF to make the button.
 
B

Bart Van der Donck

Bob Smith said:
Hi all
I have a page which contains a form.
I want a customized button with an image for the submit button, and when the
submit button has been clicked send the form to the perl script.
Now the form is no problem but the button is, so the question is how do I
create a custom button and how do I submit the form with javascript when the
button is clicked?
many thank's for any hint and help
B


Bob,

You want something like:

<form method="post" action="myperl.script">
<button onClick="document.forms[0].submit()">
<img src="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif"
width="250" height="60">
</button>
</form>

It is possible that images inside buttons are Internet Explorer only,
not sure.

Regards
Bart
 
R

Richard Cornford

You want something like:

<form method="post" action="myperl.script">
<button onClick="document.forms[0].submit()">
<img src="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif"
width="250" height="60">
</button>
</form>

No you don't. As the desired effect can be achieved with pure HTML that
is how it should be achieved, but the default type of a BUTTON element
is "submit" anyway so even this option would work as pure HTML if you
take the JavaScript onclick attribute out.
It is possible that images inside buttons are Internet Explorer only,
not sure.

Netscape 4 does not recognise the BUTTON element at all (because it was
introduced with HTML 4) but I think that images are OK as content
everywhere that BUTTON is recognised (though ALT text becomes very
relevant in speech/text browsers (and is required on IMG elements in
HTML 4 anyway)).

Richard.
 
B

Bart Van der Donck

Richard Cornford said:
You want something like:

<form method="post" action="myperl.script">
<button onClick="document.forms[0].submit()">
<img src="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif"
width="250" height="60">
</button>
</form>

No you don't. As the desired effect can be achieved with pure HTML that
is how it should be achieved, but the default type of a BUTTON element
is "submit" anyway so even this option would work as pure HTML if you
take the JavaScript onclick attribute out.

<button type="submit"> would work too, yes. It are just 2 ways to
achieve the same goal. Is that why Bob shouldn't use my code ?
However, by just taking the onClick event away, the form doesn't
submit (just quick test on IE6 here) as you say.

Netscape 4 does not recognise the BUTTON element at all (because it was
introduced with HTML 4) but I think that images are OK as content
everywhere that BUTTON is recognised (though ALT text becomes very
relevant in speech/text browsers (and is required on IMG elements in
HTML 4 anyway)).

Is ALT required on IMG elements in HTML4 ? No it is not.
About speech/text browsers: yes of course in those cases it is
relevant, or relevant as info for surfers, or when download fails or
....etc

I never met a textbrowser in my logs however. Not sure about speech
browsers, but, fairly, I would be surprised.

Bart
 
R

Richard Cornford

<button type="submit"> would work too, yes. It are just 2 ways to
achieve the same goal. Is that why Bob shouldn't use my code ?

A scripted HTML page requires support for HTML and JavaScript on the
browser. An HTML submit button (of any sort) only requires support for
HTML. If exactly the same effect can be achieved reliably with pure HTML
it is insane to use JavaScript when the browser pretty much has to have
HTML but may not have JavaScript either available or enabled. If it
exists, the reliable method is the best.
However, by just taking the onClick event away, the form doesn't
submit (just quick test on IE6 here) as you say.

<quote frome="W3C HTML 4.01 Specification"
cite="http://www.w3.org/TR/html4/interact/forms.html#h-17.5">
....
<!ATTLIST BUTTON
%attrs; -- %coreattrs, %i18n, %events --
name CDATA #IMPLIED
value CDATA #IMPLIED -- sent to server when
submitted --
type (button|submit|reset) submit -- for use as form button --
....
type = submit|button|reset [CI]
This attribute declares the type of the button. Possible values:
submit: Creates a submit button. This is the default value.
reset: Creates a reset button.
button: Creates a push button.
....
</quote>

If the HTML spec says it should then IE (or your code) is at fault.

Is ALT required on IMG elements in HTML4 ? No it is not.

Yes it is!
About speech/text browsers: yes of course in those cases it is
relevant, or relevant as info for surfers, or when download fails or
...etc

I never met a textbrowser in my logs however. Not sure
about speech browsers, but, fairly, I would be surprised.

Logs do not represent an accurate source of information about web
browsers, only about the user agent strings that those browsers choose
to broadcast (and these days that is often a matter of choice).

Which cave first, the site that is inaccessible to text browsers or the
fact that no text browsers visit it?

Richard.
 
B

Bart Van der Donck

Theoretically, you are right.
Pactically, interpretations of some W3C specs are possible. And that
is how it should be.

E.g. HTML4+:

W3C specification:
default type <button> is "submit"
Reality:
IE6 doesn't set <button> as "submit" by default
Conclusion:
Don't use that code

W3C specification:
ALT is required for IMG
Reality:
ALT is not required, but recommended
Conclusion:
You don't need to write ALTs for every IMG
Logs do not represent an accurate source of information about web
browsers, only about the user agent strings that those browsers choose
to broadcast (and these days that is often a matter of choice).

The accuracy is reasonable.

Bart
 
J

Jim Ley

IE6 doesn't set <button> as "submit" by default
Conclusion:
Don't use that code

Relying on defaults is never wise, adding type="submit" hardly costs
anything.
ALT is not required, but recommended
Conclusion:
You don't need to write ALTs for every IMG

The situation is far from the same, your first one is a bug in a
browser if it's not handled properly, missing ALT is an invalid
document, which is quite different.
The accuracy is reasonable.

Please define reasonable, and put some accurate metrics on it, for a
particular site.

Jim.
 
B

Bart Van der Donck

Relying on defaults is never wise, adding type="submit" hardly costs
anything.
Agreed



The situation is far from the same, your first one is a bug in a
browser if it's not handled properly, missing ALT is an invalid
document, which is quite different.

Agreed... Both examples were only to demonstrate that W3C
specifications of HTML4 are sometimes not enough as base for webpage
coding. Instead I use something like
(1) define which browsers I want to write for
(2) within (1) check as much browsers as possible (or available)
before putting the code into use

Please define reasonable, and put some accurate metrics on it, for a
particular site.

Reasonable = system administrators have a more or less correct view on
what browsers visit the webserver. It must be possible to broadcast a
different user-agent as Richard says. However that should be a
miniscul minority of the surfing crowd.

Bart
 
J

Jim Ley

Both examples were only to demonstrate that W3C
specifications of HTML4 are sometimes not enough as base for webpage
coding.

Marking up invalid sites is unquestionably pointless, believing valid
sites are all you should do is also pointless, but valid mark-up
doesn't prevent anything, and will catch an awful lot of errors.
Instead I use something like
(1) define which browsers I want to write for

What on incredibly odd way to develop, why not author for the web?
(2) within (1) check as much browsers as possible (or available)
before putting the code into use

So you only do any QA with the old browsers, sounds an odd way of
doing QA - I bet you charge more for your "maintenance" yeah?
Reasonable = system administrators have a more or less correct view on
what browsers visit the webserver. It must be possible to broadcast a
different user-agent as Richard says. However that should be a
miniscul minority of the surfing crowd.

No, it's the majority, in fact you probably won't find a UA which
tells the truth... Of course they might do somewhere in the string
aswell as the lies, but then you're relying on the strength of your
measuring script, I've yet to see a good one. Also of course people
reaching your webserver has little to do with people viewing your
site, and then there's the self-fulfilling aspect of logs. Could you
explain why you believe the logs are "more and less accurate" ?

Jim.
 
R

Richard Cornford

Bart Van der Donck said:
Theoretically, you are right.
Pactically, interpretations of some W3C specs are possible.
And that is how it should be.

A specification that is open to interpretation is a bad specification.
But is the phrase "This is the default value" really that unspecific? Or
the word "REQUIRED" in the DTD next to the ALT attribute on IMG?
E.g. HTML4+:

W3C specification:
default type <button> is "submit"
Reality:
IE6 doesn't set <button> as "submit" by default
Conclusion:
Don't use that code

Yes said:
W3C specification:
ALT is required for IMG
Reality:
ALT is not required, but recommended

Hence the use of the word "Required" in the DTD.
Conclusion:
You don't need to write ALTs for every IMG

To Author valid HTML 4 every image does need to have an ALT attribute.
The accuracy is reasonable.

Logs will accurately report the user agent strings broadcast by
client-side software. User agent strings are _not_ an accurate indicator
of the nature of he client-side software.

Richard.
 
B

Bart Van der Donck

Marking up invalid sites is unquestionably pointless, believing valid
sites are all you should do is also pointless, but valid mark-up
doesn't prevent anything, and will catch an awful lot of errors.


What on incredibly odd way to develop, why not author for the web?


So you only do any QA with the old browsers, sounds an odd way of
doing QA - I bet you charge more for your "maintenance" yeah?

Authoring for the web is a nice idea, but... where are the limits?
Going back to 3+ browsers? Being accessible for LYNX ? It could give a
nice feeling that your site is LYNX-compatible, but is it really
useful? I doubt

I am mostly active in field of web applications and I usually require
IE5+. This gives me enough space to use some client script, xml, css2,
tabular controls and so. Other browsers get an error message "You need
IE5+ to continue". Most of my work consists out of customer login,
intranets etc. and until now I never had someone complaining like "but
I use Netscape 2!!" or so :) People with that kind of old browsers
mostly have other browsers as well; they know what they are browsing
with and know what to expect.

I believe it's not odd to develop that way. It is a matter of what is
required for what type of thing you want to do. LOT of databases with
browser interfaces set requirements. Especially when it comes to
intra/extranet usage. There is no other choice if you want to use more
complex client scripting.

Of course when developing an "average" website for the public, the
idea must be totally different and it must be compatible for more
browsers. Basically that is a matter of choice of the webmaster - one
says "IE4+ NS4+" other says "HTML3+" other says "800*600+" etc. For
public websites I use something like IE4+ NS4+ 640*480. Now we're not
gonna discuss whether or not that should be HTML3+ or so, OK ;-)
No, it's the majority, in fact you probably won't find a UA which
tells the truth... Of course they might do somewhere in the string
aswell as the lies, but then you're relying on the strength of your
measuring script, I've yet to see a good one. Also of course people
reaching your webserver has little to do with people viewing your
site, and then there's the self-fulfilling aspect of logs. Could you
explain why you believe the logs are "more and less accurate" ?

I scan logs with ANALOG which is a well known analyser that interprets
Apache logs. I believe Apache logs are more or less accurate because I
believe that for 5 years or so. Considering the general main stream
information about Apache logs, I do not see many reasons to doubt.

Now I need to go back to work guys!

was a nice discussion, thanks
Bart
 
J

Jim Ley

Of course when developing an "average" website for the public, the
idea must be totally different and it must be compatible for more
browsers. Basically that is a matter of choice of the webmaster - one
says "IE4+ NS4+" other says "HTML3+" other says "800*600+" etc

No, most people don't say any such thing (and as my Series 60 browsers
are more powerful and contain more javasript possibilities than NN4 it
would seem particularly odd to do anything with those. The
targetting browsers is a very old and discredited way of developing
entirely. For intranets this is just as true, you may still use
certain browser features for fast/cheap development, but that should
not stop you doing everything, intranet platforms change, there's a
number of big companies who've changed browsers, or O/S or similar,
and MS require upgrading of their browsers along side O/S - which they
stop maintaining regularly. Authoring on the intranet suffers all
the same problems as on the web, but has a lot higher cost, when the
MS security upgrade is rolled out corporate wide, and all of a sudden
the holiday booking intranet stops working.
I scan logs with ANALOG which is a well known analyser that interprets
Apache logs. I believe Apache logs are more or less accurate because I
believe that for 5 years or so.

What? You never came across:
http://www.goldmark.org/netrants/webstats/
8 years ago, or
http://www.analog.cx/docs/webworks.html

If Analog doesn't claim the accuracy you're claiming, what do you know
about their excellent tool that they don't?

Jim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top