Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 17th, 2006, 04:25 PM
james.calhoun@gmail.com
Guest
 
Posts: n/a
Default 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?


  #2  
Old August 17th, 2006, 04:55 PM
plato
Guest
 
Posts: n/a
Default Re: How to use a link to change the value of a hidden field

james.calhoun@gmail.com wrote:
Quote:
I feel like this should be really easy...
Your feeling is correct.
Quote:
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

  #3  
Old August 17th, 2006, 05:15 PM
james.calhoun@gmail.com
Guest
 
Posts: n/a
Default Re: How to use a link to change the value of a hidden field

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...

  #4  
Old August 17th, 2006, 05:55 PM
Randy Webb
Guest
 
Posts: n/a
Default Re: How to use a link to change the value of a hidden field

plato said the following on 8/17/2006 12:58 PM:
Quote:
james.calhoun@gmail.com wrote:
Quote:
>I feel like this should be really easy...
>
Your feeling is correct.
>
Quote:
>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>
Quote:
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/
  #5  
Old August 17th, 2006, 07:15 PM
RC
Guest
 
Posts: n/a
Default Re: How to use a link to change the value of a hidden field

james.calhoun@gmail.com wrote:
Quote:
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>
  #6  
Old August 17th, 2006, 07:15 PM
james.calhoun@gmail.com
Guest
 
Posts: n/a
Default Re: How to use a link to change the value of a hidden field

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


sorry and thanks for the help!

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.