How to use a link to change the value of a hidden field

J

james.calhoun

I feel like this should be really easy... I want a hidden field in a
form to have its value defined when someone clicks on a link.

So if they click on link "A" the value of the hidden field becomes "A",
while if they click "B" the value of hidden field becomes "B"

Help?
 
P

plato

I feel like this should be really easy...

Your feeling is correct.
So if they click on link "A" the value of the hidden field becomes "A",
while if they click "B" the value of hidden field becomes "B"

<a href="linkA.php" onclick="document.getElementById( 'hiddenField'
).value = 'A'";>...</a>
<a href="linkB.php" onclick="document.getElementById( 'hiddenField'
).value = 'B'";>...</a>

I'd point out, though, that this seems entirely useless because once
you click a link, the page leaves the form. If you want to use the
link as a button, there are better ways to do that in [X]HTML.

Hope this is what you were looking for.

-plato
 
J

james.calhoun

Ok, cool... we are on the way!

So, basically, i am trying to imitate a form selection.. but I want
people to be able to click on nice pretty divs, and when they click on
them, i want the the name of the item they clicked on to be stored
along with other form data.

So I was thinking, make a hidden input, whose value is a variable...
and that variable is set by an anchor link.

So a user clicks on the link surrounding an Image (the link doesnt go
anywhere, it just has a nice rollover effect, and the click action
changes the div style), and then I take the name of the image they
clicked on and pass that into the variable and then call that variable
in the hidden field when the form is submitted.

Is that completely illogical? is there a better way to accomplish that?

The options to be selected will not change that often, so I thought i
could do something like

<a href="#" onClick="setVariable(imageA)">

then something like

<input type="hidden" value="variable">


But since I really dont know JavaScript, im trying to figure out how to
write a function that can capture that data and pass it on...
 
R

Randy Webb

plato said the following on 8/17/2006 12:58 PM:
Your feeling is correct.


<a href="linkA.php" onclick="document.getElementById( 'hiddenField'
).value = 'A'";>...</a>
<a href="linkB.php" onclick="document.getElementById( 'hiddenField'
).value = 'B'";>...</a>

I'd point out, though, that this seems entirely useless because once
you click a link, the page leaves the form.

Not if you return false in the onclick event handler:

If you want to use the link as a button, there are better ways to do
that in [X]HTML.

With XHTML's support on the web, it's not even worth mentioning. But the
button is:

<button onclick="document.theFormID.theHiddenField.value='Something
else'">Set it without using the gEBI crutch</button>
 
R

RC

I feel like this should be really easy... I want a hidden field in a
form to have its value defined when someone clicks on a link.

So if they click on link "A" the value of the hidden field becomes "A",
while if they click "B" the value of hidden field becomes "B"

<script language="JavaScript">

function getValue(form, thisValue) {
form.myHiddenField.value = thisValue;
alert(form.myHiddenField.value);
}

</script>

<form name="form0">
<input type="hidden" name="myHiddenField" value="" />

<input type="button" value="A"
onClick="getValue(this.form, this.value)" ?>

<a href="#" onClick="getValue(document.form0, 'B')">B</a>
</form>
 
J

james.calhoun

Please disregard... I figured it out... way easier then I thought...


sorry and thanks for the help!
 

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top