Tall order: text hyperlink that sets var value + submits form

R

Randell D.

Folks,

I am working on a contact db using PHP and MySQL. My results so far outputs
a slimed down version of records to the browser. I would like to implement
a method whereby the user can click on a text link which will then show the
full record. I don't want to have hyperlinks with values incorporated in
the link (thus, I don't want to have http://www.example.com?abc=1234) - I
prefer to use a POST method thus what I would like to do is have my output
listed inside a form. Each record would have unique hidden form value using
either a <INPUT TEXT> or <INPUT CHECKBOX>. Each record would have a
hyperlink so that when the hyperlink is pressed, its respective unique
record ID is noted, then the form submitted.

I know something like this is possible - I can work out the PHP/MySQL part
of it myself - But my javascript is still far too junior to accomplish
something like this.

Can someone help steer me in the right direction? If they know of a working
example I'm sure I could read and re-write the script to fit in with my
project...

Breaking my problem down a bit... I know I can have an onClick event in my
<A HREF> tag... But how can I have it set a value in a hidden box, and then
post the form?

All help, via the newsgroup would be much appreciated...

thanks,
randelld
 
D

David Dorward

Randell said:
I am working on a contact db using PHP and MySQL. My results so far
outputs a slimed down version of records to the browser. I would like to
implement a method whereby the user can click on a text link which will
then show the full record. I don't want to have hyperlinks with values
incorporated in the link (thus, I don't want to have
http://www.example.com?abc=1234) - I prefer to use a POST method

Why? You aren't changing anything on the server, so this is what GET is
designed for. Aside from being easier to deal with, it will allow people to
bookmark specific entries.
thus what I would like to do is have my output
listed inside a form. Each record would have unique hidden form value
using either a <INPUT TEXT> or <INPUT CHECKBOX>.

Why not using type="hidden"? That's designed for hidden inputs?
Each record would have a hyperlink so that when the hyperlink is pressed,
its respective unique record ID is noted, then the form submitted.

Great. So you are depending on JavaScript. This is not a good idea. The most
important thing to learn about JavaScript, is when not to use it.

http://tom.me.uk/scripting/submit.asp
Breaking my problem down a bit... I know I can have an onClick event in my
<A HREF> tag... But how can I have it set a value in a hidden box, and
then post the form?

It sounds like you would be better off having multiple forms, then trying to
edit one form based on the user selection.
 
R

Randell D.

David Dorward said:
Why? You aren't changing anything on the server, so this is what GET is
designed for. Aside from being easier to deal with, it will allow people to
bookmark specific entries.


Why not using type="hidden"? That's designed for hidden inputs?


Great. So you are depending on JavaScript. This is not a good idea. The most
important thing to learn about JavaScript, is when not to use it.

http://tom.me.uk/scripting/submit.asp


It sounds like you would be better off having multiple forms, then trying to
edit one form based on the user selection.


First off... I did mean to refer to a HIDDEN tag - the words didn't come out
the way I anticipated - my fault - sorry for being unclear...

Anyway... Your proposed solution though: I had thought of something like
that (though I have to admit, the CSS idea was new to me and a nice touch) -
but the solution doesn't meet my problem entirely... I would prefer to have
a numeric value passed (the record ID) as opposed to the the value of the
submit button... Thus if I were to have something like a hidden field, a
hyperlink around the persons name, address and other contact details which,
when clicked, passed a record id (numeric value) to the hidden field, and
then submitted the form... that is more preferable.

I've read the link you supplied - It briefly details incorrect usages and
summarises it with "all are very poor usage of the A element". In my
ignorance, I would beg to differ (I'm not looking to get flamed but am open
to being educated through this newsgroup).

Why else do the A tag have the onClick feature? I know that the A tag is for
navigational purposes, but the onClick feature allows one extra
functionality...

Most modern day graphical browsers have javascript - It helps reduce the
load on the server and share some of the processing with the client. If
users are to disable javascript, then they disable functionality and are
unlikely to see something any more informative then the equivalent of junk
mail that would come through the door (ie fixed/static and less
interactive). Putting it bluntly, one doesn't get something for nothing in
this world - Even if its just free (as in beer) - folk always get something,
be it a laugh or a smile (ie happiness), information, goods or cash for the
bank...

Roughly speaking one could compare javascript to whistles and bells, music
and lights in a bricks and mortar business. If given the choice of two
stores selling the same goods on the same street, I'd be more likely to
enter the brighter, colourful and more welcoming one then the grey bricked
1950s paint job dimly lit uuncomfortably cold looking building...

While I do intend to design my pages to have a static (non javascript)
navigation on them, I aim to place less than 10% of my resources in this way
as if they (the client/viewers) are not interested in helping me help them
then they can spend extra time navigating elsewhere to find their info... I
know its crude - but I aim to create an application online (small time
application service provider) and I have 18months experience identifying my
market... During this time I analysed log files and discovered less than 2%
(of my likely market) had javascript disabled - some months went by where
less than one tenth of 1% were non-javascript browsers.

So... again... I do like your CSS solution - kudos for that and its
something I'm sure I will refer to later - but for now, I'd prefer to have a
clickable hyperlink that writes a numeric value in to a hidden field and
then submits the form...

Can you help me there?

Cheers
Randell D.
 
R

Randell D.

Randell D. said:
Folks,

I am working on a contact db using PHP and MySQL. My results so far outputs
a slimed down version of records to the browser. I would like to implement
a method whereby the user can click on a text link which will then show the
full record. I don't want to have hyperlinks with values incorporated in
the link (thus, I don't want to have http://www.example.com?abc=1234) - I
prefer to use a POST method thus what I would like to do is have my output
listed inside a form. Each record would have unique hidden form value using
either a <INPUT TEXT> or <INPUT CHECKBOX>. Each record would have a
hyperlink so that when the hyperlink is pressed, its respective unique
record ID is noted, then the form submitted.

I know something like this is possible - I can work out the PHP/MySQL part
of it myself - But my javascript is still far too junior to accomplish
something like this.

Can someone help steer me in the right direction? If they know of a working
example I'm sure I could read and re-write the script to fit in with my
project...

Breaking my problem down a bit... I know I can have an onClick event in my
<A HREF> tag... But how can I have it set a value in a hidden box, and then
post the form?

All help, via the newsgroup would be much appreciated...

thanks,
randelld

I think I got what I was looking for... my lack of javascript experience had
made my previous attempts to fail because I had neglected to use 'value' (an
object? class? whatever its called) in my original script... but for anyone
that is interested in playing around themselves... this is my rough test
script that I plan on implementing with my PHP/MySQL scripts... Thank to all
who offered help via posts and emails (newsposts are always preferable).

<script language="JavaScript" type="text/JavaScript">
function one(myvalue)
{ document.form1.myname.value=myvalue;
return(TRUE);
}
</script>

<form name="form1" action="" method="post">Name:
<input name="myname" type="text" value="">
<a href="#" onClick="one(3); return">Click Here</a>
</form>
 
D

David Dorward

Randell said:
I've read the link you supplied - It briefly details incorrect usages and
summarises it with "all are very poor usage of the A element". In my
ignorance, I would beg to differ (I'm not looking to get flamed but am
open to being educated through this newsgroup).

Why else do the A tag have the onClick feature?

Because all rendered elements have an onclick event! And because you can do
USEFUL things with it that don't cause a page to depend on JavaScript.

For instance:

<h3 id="sheep">A subheading: Sheep</h3>

and somewhere else on the page:

.... however, <a href="#sheep"
onclick="document.getElementById('sheep').style.backgroundColor='yellow';">sheep</a>
are a special case.

(A nicer version can be seen at said:
I know that the A tag is for navigational purposes, but the onClick
feature allows one extra functionality...

Yes - EXTRA.
Most modern day graphical browsers have javascript

And a lot of people disabled it
- It helps reduce the load on the server and share some of the processing
with the client.

Using JavaScript to submit a form instead of a submit button does not reduce
the load on the server.
If
users are to disable javascript, then they disable functionality and are
unlikely to see something any more informative then the equivalent of junk
mail that would come through the door (ie fixed/static and less
interactive).

The great thing about the web is that its very easy to design a page that it
static and less interactive for users who don't have JavaScript, but has
flashy effects for those who do.
Roughly speaking one could compare javascript to whistles and bells, music
and lights in a bricks and mortar business. If given the choice of two
stores selling the same goods on the same street, I'd be more likely to
enter the brighter, colourful and more welcoming one then the grey bricked
1950s paint job dimly lit uncomfortably cold looking building...

See my previous paragraph in this post.
While I do intend to design my pages to have a static (non javascript)
navigation on them, I aim to place less than 10% of my resources in this
way as if they (the client/viewers) are not interested in helping me help
them then they can spend extra time navigating elsewhere to find their
info...

Not all users have don't run JavaScript do so by choice, and there is
nothing stopping you from writing static HTML... which looks nicer if the
user has CSS... and gets flashy if they have JavaScript. Good JavaScript is
a great deal about manipulating a page rather then adding to it.
 
T

Thomas 'PointedEars' Lahn

David said:
Because all rendered elements have an onclick event!

You have a strange idea of "rendered elements." According to the HTML 4.01
Specification, the `onclick' attribute is valid for "All elements but
APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME,
ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE."[1] I cannot find a definition
of "rendered elements" in the Specification, however I do consider APPLET,
BR, FONT, FRAME and IFRAME to be rendered elements as a rendering engine
(like Netscape Gecko) is required to display them.

But no matter that intrinsic event handlers are part of HTML 4.01, their
support depends on the DOM of the UA.[2] `img' elements in the NS4-DOM,
e.g., have no `onclick' event handler (at least none that is working), so
the `a' element and its `onclick' handler is required there if you want
to execute JavaScript code when clicking an image.


PointedEars
___________
[1] http://www.w3.org/TR/html4/index/attributes.html
[2] http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.3
 
J

Jim Ley

David Dorward wrote:
however I do consider APPLET,
BR, FONT, FRAME and IFRAME to be rendered elements as a rendering engine
(like Netscape Gecko) is required to display them.

APPLET, FRAME, IFRAME are containers for other content - they are not
rendered, the content is. BR is not rendered (it takes no space -
what would you click on?) FONT is the exception certainly.
so
the `a' element and its `onclick' handler is required there if you want
to execute JavaScript code when clicking an image.

In NN4, which is not an HTML 4.01 user agent.

Jim.
 
T

Thomas 'PointedEars' Lahn

Jim said:
APPLET, FRAME, IFRAME are containers for other content - they are not
rendered,

IBTD, what do you think Gecko does when I specify

<iframe
src="foobar.html"
width="200" height="100"
style="width:50%; border:2px solid red"<a href="foobar.html">blurb</a>
</iframe>

?
the content is. BR is not rendered

Depends on what you call `(to) render'. It is an interpreted element
that results in different display, namely a hard line-break.
In NN4, which is not an HTML 4.01 user agent.

Which (if true) is irrelevant here since it was only an example for the fact
that recommended event( handler)s need not to be part of the DOM of the UA.
OTOH, there are proprietary event( handler)s supported only by specific
UAs, like IE's `onmousewheel'.


PointedEars
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top