473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Passing Data without Submit/Input

I want to get the user's choice of some menu items, and pass them to a
(PHP) page in the URL, rather than with "Submit" button. I tried
this, but it doesn't work:

<a href="pagetwo.php?says=meaning"><img src="smiley.gif"></a>

Pick one from drop-down menu:
<p>
<form>
<select name=meaning>
<option>Dopey
<option>Sneezey
<option>Grumpy
</select>
</form>
Jul 23 '05 #1
16 9503

"Ben Sharvy" <bs*****@mac.com> wrote in message
news:d1**************************@posting.google.c om...
I want to get the user's choice of some menu items, and pass them to a
(PHP) page in the URL, rather than with "Submit" button. I tried
this, but it doesn't work:

<a href="pagetwo.php?says=meaning"><img src="smiley.gif"></a>
Replace with:
<script type="text/javascript">
document.write ('<a
onclick="document.forms['myForm'].submit();"><img src="smiley.gif"></a>');
</script>

Use script to write this link, because if Javascript support is unavailable
or turned off then the link wouldn't work anyway. In that case, it's replace
below, inside a NOSCRIPT element, by the Submit button that you're trying to
avoid.

Pick one from drop-down menu:
<p>
<form>
Replace with:
<form id="myForm" action="pagetwo.php" method="get">
<select name=meaning>
<option>Dopey
<option>Sneezey
<option>Grumpy
</select>
Insert:
<noscript>
<input type="submit" name="submit" value="Submit">
</noscript>
</form>


Jul 23 '05 #2
Isn't there a way to do it without javascript?
Jul 23 '05 #3
bs*****@mac.com (Ben Sharvy) wrote:
Isn't there a way to do it without javascript?


No.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 23 '05 #4
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:l5********************************@4ax.com
Isn't there a way to do it without javascript?


No.


Err...

<input type="image" src="..." ...>

See :
http://www.w3.org/TR/html401/interac....html#h-17.4.1

Jul 23 '05 #5
"Pierre Goiffon" <pg******@nowhere.invalid> wrote:
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:l5********************************@4ax.com
Isn't there a way to do it without javascript?


No.


Err...

<input type="image" src="..." ...>


That doesn't do what he wanted to do. He wants a link outside of the
form.
--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 23 '05 #6
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:oa********************************@4ax.com
Isn't there a way to do it without javascript? No.
Err... <input type="image" src="..." ...>
That doesn't do what he wanted to do. He wants a link outside of the
form.


I can't understand the difference between the solution you proposed :

----
<form id="myForm" action="pagetwo.php" method="get">
....
<script type="text/javascript">
document.write ('<a
onclick="document.forms['myForm'].submit();"><img src="smiley.gif"></a>');
</script>
<noscript>
<input type="submit" name="submit" value="Submit">
</noscript>
----

And this other one :

----
<form id="myForm" action="pagetwo.php" method="get">
....
<input type="image" src="smiley.gif" ...>
----

Can you please explain ?

Jul 23 '05 #7
"Pierre Goiffon" <pg******@nowhere.invalid> wrote:
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:oa********************************@4ax.com
> Isn't there a way to do it without javascript? No. Err... <input type="image" src="..." ...>

That doesn't do what he wanted to do. He wants a link outside of the
form.


I can't understand the difference between the solution you proposed :

----
<form id="myForm" action="pagetwo.php" method="get">
...
<script type="text/javascript">
document.write ('<a
onclick="document.forms['myForm'].submit();"><img src="smiley.gif"></a>');
</script>
<noscript>
<input type="submit" name="submit" value="Submit">
</noscript>
----

And this other one :

----
<form id="myForm" action="pagetwo.php" method="get">
...
<input type="image" src="smiley.gif" ...>
----

Can you please explain ?


I'm sorry, it was a brain fart. You're right. Never mind.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 23 '05 #8
Harlan Messinger <hm*******************@comcast.net> wrote:
"Pierre Goiffon" <pg******@nowhere.invalid> wrote:
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:oa********************************@4ax.com
>> Isn't there a way to do it without javascript?

> No.

Err...

<input type="image" src="..." ...>

That doesn't do what he wanted to do. He wants a link outside of the
form.


I can't understand the difference between the solution you proposed :

----
<form id="myForm" action="pagetwo.php" method="get">
...
<script type="text/javascript">
document.write ('<a
onclick="document.forms['myForm'].submit();"><img src="smiley.gif"></a>');
</script>
<noscript>
<input type="submit" name="submit" value="Submit">
</noscript>
----

And this other one :

----
<form id="myForm" action="pagetwo.php" method="get">
...
<input type="image" src="smiley.gif" ...>
----

Can you please explain ?


I'm sorry, it was a brain fart. You're right. Never mind.


No, wait--I *was* right; when I wrote the above, I wasn't remembering
part of my original reasoning. Part of what he wanted (at least, as I
understood it) was to have the link outside of the form. The code I
provided wasn't meant to be inserted into the form, it was meant to
replace the link the OP was trying to use, in the same position.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 23 '05 #9
Harlan Messinger wrote:
<script type="text/javascript">
document.write ('<a onclick="document.forms['myForm'].submit();"><img
src="smiley.gif"></a>');
</script>

Use script to write this link, because if Javascript support is
unavailable or turned off then the link wouldn't work anyway. In that
case, it's replace below, inside a NOSCRIPT element, by the Submit
button that you're trying to avoid.


This is not the best authoring practices. What if js is enabled but the
code contains an error? Neither the js submit nor the <noscript> submit
button will be available.

Better solution: create a fully functioning <form>, and use js to modify
the dom, removing the <input type=submit> and adding a js submit mechanism.

But then, the best solution for the op is to KISS, and use a normal form.

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #10
Ben Sharvy wrote:
I want to get the user's choice of some menu items, and pass them to
a (PHP) page in the URL, rather than with "Submit" button.
What is wrong with a submit button? If you want to pass the data using
via url, then use the GET method:

<form method="get" action="myscript.php">
I tried this, but it doesn't work:

<a href="pagetwo.php?says=meaning"><img src="smiley.gif"></a>

Pick one from drop-down menu:
<p>
<form>
<select name=meaning>
<option>Dopey
<option>Sneezey
<option>Grumpy
</select>
</form>


A form can only pass information via http. You can try js to accomplish
this, perhaps by modifying the href attribute of an <a> element, but why
go through all that bother when a basic form will work? That is, after
all, what the <form> element is meant for.

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #11

"Brian" <us*****@julietremblay.com.invalid> wrote in message
news:wg*********************@bgtnsc04-news.ops.worldnet.att.net...
Harlan Messinger wrote:
<script type="text/javascript">
document.write ('<a onclick="document.forms['myForm'].submit();"><img
src="smiley.gif"></a>');
</script>

Use script to write this link, because if Javascript support is
unavailable or turned off then the link wouldn't work anyway. In that
case, it's replace below, inside a NOSCRIPT element, by the Submit
button that you're trying to avoid.
This is not the best authoring practices. What if js is enabled but the
code contains an error?


Don't use programming because it might be in error? Following that
philosophy, none of the software you use every day would have ever gotten
out the door. Obviously when anyone publishes software, it's after they're
satisfied that it's basically correct. Presumably, the man is going to
*test* his page before he releases it. It won't take him long to fully test
it--this isn't control software for satellite deployment or anything like
that.
Neither the js submit nor the <noscript> submit
button will be available.
If he accidentally types

<input type="sbumit" ...

the page will also be broken.

Better solution: create a fully functioning <form>, and use js to modify
the dom, removing the <input type=submit> and adding a js submit mechanism.
But then, the best solution for the op is to KISS, and use a normal form.


For the most part I agree.

Jul 23 '05 #12
Harlan Messinger wrote:
"Brian" wrote...
Harlan Messinger wrote:
<script type="text/javascript">
document.write ('<a
onclick="document.forms['myForm'].submit();"><img
src="smiley.gif"></a>');
</script>

Use script to write this link, because if Javascript support is
unavailable or turned off then the link wouldn't work anyway. In
that case, it's replace below, inside a NOSCRIPT element, by the
Submit button that you're trying to avoid.
This is not the best authoring practices. What if js is enabled but
the code contains an error?

Don't use programming because it might be in error?


No. Use programming in the safest way possible. In the context of the
www, that means start with a page that functions without js, then add js
to change that page if js is enabled. If you code the js correctly, then
the page will work when js is disabled; it will work when js is enabled
but the code goes awry; and it will work when js is enabled and works.
Presumably, the man is going to *test* his page before he releases
it.


This is the www, though. Noone can test in every release of every
browser. At least in principle, a browser can implement some js, but not
the document.write method. In that case, your suggestion would fail,
since the browser would not write the js link, but, since js is enabled,
it would ignore the contents of the <noscript> element.
Neither the js submit nor the <noscript> submit button will be
available.

If he accidentally types

<input type="sbumit" ...

the page will also be broken.


Fair enough, but a validator will point out that error. I suppose a js
debugger might point out js bugs, but I'm not sure it can pick up all
possible problems. You might write code that is free from errors, and
works in MSIE and Mozilla, but fails because of a js bug in Opera
7.1/WinXP. If you don't test in that particular version of Opera, you've
got a problem.

Take the op's request: instead of document.write, you create a js
routine that adds an onsubmit handler or a new link, then removes the
<input type="submit"> from the DOM. If some browser chokes on the code,
it will never get to the remove part of the script, and the page will
still work. Such a routine is not fool-proof, but is much safer than
assuming your code will always execute correctly.

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #13
Brian wrote:
Harlan Messinger wrote:
Brian wrote...

Don't use programming because it might be in error?

No. Use programming in the safest way possible.


That is, "No, I don't mean that you shouldn't use a programming language
because it might be in error. I only mean that you should use a
programming language in the safest way possible."

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #14
Brian <us*****@julietremblay.com.invalid> wrote:
Harlan Messinger wrote:
[snip]
Presumably, the man is going to *test* his page before he releases
it.


This is the www, though. Noone can test in every release of every
browser. At least in principle, a browser can implement some js, but not
the document.write method.


Isn't document.write an ancient, core Javascript method? I think it's
fair to assume that *if* a browser implements Javascript, it
implements its core functionality, at least to the extent that we
assume that browsers that implement HTML implement submit buttons.
In that case, your suggestion would fail,
since the browser would not write the js link, but, since js is enabled,
it would ignore the contents of the <noscript> element.
Neither the js submit nor the <noscript> submit button will be
available.

If he accidentally types

<input type="sbumit" ...

the page will also be broken.


Fair enough, but a validator will point out that error. I suppose a js
debugger might point out js bugs, but I'm not sure it can pick up all
possible problems. You might write code that is free from errors, and
works in MSIE and Mozilla, but fails because of a js bug in Opera
7.1/WinXP. If you don't test in that particular version of Opera, you've
got a problem.


A version of Opera could just as easily come out with a bug in the
submit button.

Take the op's request: instead of document.write, you create a js
routine that adds an onsubmit handler or a new link, then removes the
<input type="submit"> from the DOM. If some browser chokes on the code,
it will never get to the remove part of the script, and the page will
still work. Such a routine is not fool-proof, but is much safer than
assuming your code will always execute correctly.


I thought you were kidding when your first suggested that.
Interesting, on second thought. But--I believe document.write has
older and broader support than does DOM/DHTML code that can remove
elements.
--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 23 '05 #15
Harlan Messinger (hm*******************@comcast.net) wrote:
: Brian <us*****@julietremblay.com.invalid> wrote:

: >Harlan Messinger wrote:

: [snip]

: >> Presumably, the man is going to *test* his page before he releases
: >> it.
: >
: >This is the www, though. Noone can test in every release of every
: >browser. At least in principle, a browser can implement some js, but not
: >the document.write method.

: Isn't document.write an ancient, core Javascript method? I think it's
: fair to assume that *if* a browser implements Javascript, it
: implements its core functionality, at least to the extent that we
: assume that browsers that implement HTML implement submit buttons.

I don't think he ever meant to suggest that any browser might have a bug
with document.write, I'm sure that choosing "document.write" was just the
easiest possible way to illustrate his point.

I more realistic bug might be something like "...an incompatibility with
the dom model when multiple frames are in use after selecting the back
button...". But if he's going to make up a bug (like I just did), why not
make up a bug that is simpler to explain?

And in my hyperthetical example, sure enough, his code would probably not
be able to remove the submit link due to the hyperthetical
"incompatibility with the dom model", and therefore the form would still
have at least one way to do the submit.

Jul 23 '05 #16
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:6p********************************@4ax.com
The code I
provided wasn't meant to be inserted into the form, it was meant to
replace the link the OP was trying to use, in the same position.


Oh, OK. I missed that. Thanks

Jul 23 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
2
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
3
by: Patrick Olurotimi Ige | last post by:
How can i send LOGON_USER or User.Identity.Name to the Database? I'm working on a survey which is intranet based with Windows Authentication. I can get the current user by calling LOGON_USER or...
7
by: Khai | last post by:
First off, yes, I understand the crapload of tutorials out there, (well, rather, I understand there /are/ a crapload of tutorials out there), the problem is my comprehension. I'm trying to pass...
4
by: jej1216 | last post by:
I'm pretty new to PHP and MySQL. I have managed to create a form that inserts data to MySQL and to create a form to search the DB. Now here is my problem. I am unsuccessful coding a hidden...
3
by: ToddFur | last post by:
I see several postings on this but I am still unable to figure out my problem. I can pass the values of my text field but not radio button (or even checkboxes). My PHP file <?php //declare...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.