473,396 Members | 1,970 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,396 software developers and data experts.

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

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?

Aug 17 '06 #1
5 6824
ja***********@gmail.com wrote:
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

Aug 17 '06 #2
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...

Aug 17 '06 #3
plato said the following on 8/17/2006 12:58 PM:
ja***********@gmail.com wrote:
>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.
Not if you return false in the onclick event handler:

<a href="http://www.google.com/" onclick="return false">Google - Maybe</a>
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>
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 17 '06 #4
RC
ja***********@gmail.com wrote:
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>
Aug 17 '06 #5
Please disregard... I figured it out... way easier then I thought...
sorry and thanks for the help!

Aug 17 '06 #6

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

Similar topics

4
by: Dodo | last post by:
Is it possible to create a link that can post a value to an ASP page without java?
8
by: timmy_dale12 | last post by:
I need help with this one. I have a function that pastes a row. In each row i am pasting a link which is to call a date picker javascript function. This is the code that pastes the link : link =...
8
by: Matt Herson | last post by:
I have been trying to find a way to use JavaScript to change the value of a hidden field on submit. I am already invoking a JavaScript to handle the validation on submit. The reason I need to...
2
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of...
4
by: kschneider | last post by:
Assume there's a form with it's action attribute all set to post to a URL, but without a submit control. Form submission is done via a link and I want to prevent the classic "double submit"....
2
cassbiz
by: cassbiz | last post by:
I may be in the wrong forum so Ronald don't shoot :) In my code I have an option box to choose a number - works fine. I want to carry over the new value to another field to do a recalculation. ...
13
by: Casimir Pohjanraito | last post by:
I have a list of links, with a thumbnail image hidden(resized) next to the link. Complete html&css at end of this post. CSS for the link resizes the image on a:hover. All is good, except the...
6
by: K Viltersten | last post by:
I have the following button: <asp:LinkButton id="Btn" runat="server" text="Click"> </asp:LinkButton> I have added an action listener in the javascript where I change the text on it:...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.