Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 12-12-2006, 04:19 PM Form Problem
larryweiss's Avatar
Super Talker

Posts: 117
Location: NEW YORK
Trades: 0
Is it possible to set the value of two seperate hidden inputs using one select. The select could be a radio group or a drop down menu.

If the question is not clear, here is an example:

Paypal button:

STANDARD CODE

<input type="hidden" name="item_name">
<select name="item_name">
<option value="1">1</option>
<option value="2">2</option>
</select>

<input type="hidden" name="amount" >
<select name="amount">
<option value="200">200.00</option>
<option value="300">300.00</option>
<option value="400">400.00</option>
</select>

Can you achieve these two inputs

<input type="hidden" name="item_name">
<input type="hidden" name="amount" >

Using a single selecting element, as with a radio group or a single selection menu?
__________________
Larry Weiss


Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
larryweiss is offline
Reply With Quote
View Public Profile Visit larryweiss's homepage!
 
 
Register now for full access!
Old 12-12-2006, 05:01 PM Re: Form Problem
blackhawkpowers's Avatar
Ultra Talker

Posts: 313
Name: Dustin
Location: GA
Trades: 0
might be a bit confused on the question but hidden inputs are not changed by a user....... your code there is always going to return a value of "200.00" if it's hidden.
__________________
A patch is a piece of software which replaces old bugs with new bugs.

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
blackhawkpowers is offline
Reply With Quote
View Public Profile Visit blackhawkpowers's homepage!
 
Old 12-12-2006, 05:12 PM Re: Form Problem
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I've moved this thread to the JavaScript forum since that's likely where your solution will be. You should be able to set up what you want with some JavaScript, DOM, and CSS.

The basic idea would be to have your select call a JavaScript function when it changes. The function could then alter the values of your hidden inputs based on the selection.

If you search a little around the phrase 'dynamic forms' you can probably find some code that's close enough to what you want.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 12-12-2006, 05:48 PM Re: Form Problem
larryweiss's Avatar
Super Talker

Posts: 117
Location: NEW YORK
Trades: 0
Your answers show my profound confusion about the subject. Let me try again.

Is it possible to set the value of two inputs using one select. The select could be a radio group or a drop down menu.

If the question is not clear, here is an example:

Paypal button:

STANDARD CODE

<select name="item_name">
<option value="a">A</option>
<option value="b">B</option>
</select>


<select name="amount">
<option value="200">200.00</option>
<option value="300">300.00</option>
<option value="400">400.00</option>
</select>

END STANDARD CODE




QUESTION
Can you achieve these two values:
item_name="Value determined by using input A"
amount="Value ALSO determined by using input A"
__________________
Larry Weiss


Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE

Last edited by larryweiss; 12-12-2006 at 06:08 PM..
larryweiss is offline
Reply With Quote
View Public Profile Visit larryweiss's homepage!
 
Old 12-13-2006, 01:59 AM Re: Form Problem
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Larry I think I understand, but let me check. What you want is for when someone makes a selection from the first <select> then the value of the second <select> is automatically chosen for them. Is that right?

One more question with that is will the person filling out the form be able to change that second <select> so maybe they choose option A for the item_name, which sets the value of the amount, and then change to a different amount while still keeping A as the item_name?

Also if the item_name is automatically selecting the amount does the customer need to have the amount choices presented to them?

If the customer can only change the amount by changing the item_name then couldn't they both be in the same select.

<select name="item_name">
<option value="a">A: 200.00</option>
<option value="b">B: 300.00</option>
</select>

If that works I think it's the easiest way to go. If not then I still think you can use some JavaScript to set the second input.

You would add an onchange to the first select. That onchange would call a function that would set the other select.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 12-13-2006, 02:03 AM Re: Form Problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I think you are asking if there is a way to link two inputs so selecting one will have an effect on the other, but the question is extremely vague.


On the other hand of course you could be asking how to retrieve more details from a database about the item selected and pass that on to the recieving end.
That would be a server side operation.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-18-2006, 12:19 AM Re: Form Problem
larryweiss's Avatar
Super Talker

Posts: 117
Location: NEW YORK
Trades: 0
Quote:
Originally Posted by vangogh View Post
Larry I think I understand, but let me check. What you want is for when someone makes a selection from the first <select> then the value of the second <select> is automatically chosen for them. Is that right?


If the customer can only change the amount by changing the item_name then couldn't they both be in the same select.

<select name="item_name">
<option value="a">A: 200.00</option>
<option value="b">B: 300.00</option>
</select>

Yes. the amount is completely bound to the item_name. For instance, if item_name 18"x24" is selected, then the amount is $5.10, and there should not be any customer input to change that, as that is the price of the 18 x 24.

As I understand your example, using
<option value="b">B: 300.00</option>
Would set the "item_name" to "B: 300.00"
but would do nothing for the "amount".

Is that correct?
__________________
Larry Weiss


Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
larryweiss is offline
Reply With Quote
View Public Profile Visit larryweiss's homepage!
 
Old 12-18-2006, 12:22 AM Re: Form Problem
larryweiss's Avatar
Super Talker

Posts: 117
Location: NEW YORK
Trades: 0
Quote:
Originally Posted by chrishirst View Post
I think you are asking if there is a way to link two inputs so selecting one will have an effect on the other.
That is exactly what I am asking.
__________________
Larry Weiss


Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
larryweiss is offline
Reply With Quote
View Public Profile Visit larryweiss's homepage!
 
Old 12-18-2006, 08:25 AM Re: Form Problem
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by larryweiss View Post
Is it possible to set the value of two seperate hidden inputs using one select. The select could be a radio group or a drop down menu.

If the question is not clear, here is an example:

Paypal button:

STANDARD CODE

<input type="hidden" name="item_name">
<select name="item_name">
<option value="1">1</option>
<option value="2">2</option>
</select>

<input type="hidden" name="amount" >
<select name="amount">
<option value="200">200.00</option>
<option value="300">300.00</option>
<option value="400">400.00</option>
</select>

Can you achieve these two inputs

<input type="hidden" name="item_name">
<input type="hidden" name="amount" >

Using a single selecting element, as with a radio group or a single selection menu?
Try this example. If it does what you want, I'll explain exactly how to use it, if it's not clear already.
The 'hidden' inputs are replaced with text types to demonstrate the value changes.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<TITLE>TEST PAGE</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
</HEAD>
<BODY>
<FORM name='f1'>

 <select onchange='selectToHidden(this, h1Values, h2Values)'>
   <option>-Choose-
   <option>1
   <option>2
   <option>3
   <option>4
 </select>
 
<BR><BR><BR><BR><BR><BR>

<input type='text' size='10' name='h1'>&lt;- These values could be<BR>
<input type='text' size='10' name='h2'>&lt;- changed to type hidden.

</FORM>

<SCRIPT type='text/javascript'>

h1Values=['h1','tom','dick','harry','jim'];
h2Values=['h2','apples','oranges','pears','mangoes'];

function selectToHidden(box)
{
 for(var i=1; i<arguments.length; i++)
  box.form[arguments[i][0]].value=(box.selectedIndex > 0) ? arguments[i][box.selectedIndex] : '';
}

</SCRIPT>
</BODY>
</HTML>
logic ali is offline
Reply With Quote
View Public Profile
 
Old 12-25-2006, 01:51 AM Re: Form Problem
larryweiss's Avatar
Super Talker

Posts: 117
Location: NEW YORK
Trades: 0
Bulls-Eye



What do I change to "amount" and "item_name"
__________________
Larry Weiss


Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
larryweiss is offline
Reply With Quote
View Public Profile Visit larryweiss's homepage!
 
Old 12-26-2006, 04:33 PM Re: Form Problem
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Larry you wouldn't need to actually change the names to amount and item_name, but if you want to it would be the h1Values and h2Values. Make sure the values you want are in the arrays for each.

Also if you do change the names of the arrays make sure to change the line:

<select onchange='selectToHidden(this, h1Values, h2Values)'>

to reflect the new names. You also need to make sure to keep 'h1' and 'h2' in the arrays where they are or you will need to change the names on the inputs.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 12-28-2006, 09:27 PM Re: Form Problem
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by larryweiss View Post
Bulls-Eye



What do I change to "amount" and "item_name"
The function takes as its second and subsequent parameters the names of the array(s) holding the data to be sent to the other elements in the same form. You can specify as many as desired.
The first element in each array, represents the name of the target element.

If "amount" and "item_name" are the names of your hidden fields in the same form, you might create two arrays like this:
Code:
amountValues=['amount','tom','dick','harry','jim'];
itemValues=['item_name','apples','oranges','pears','mangoes'];
where the first element in each represents the name of the target element.

Each array must contain sufficient elements to match all the options in the select, except the first option, which is not acted upon.

Then in the select tag, you would have:
Code:
onchange='selectToHidden(this, amountValues, itemValues)'
logic ali is offline
Reply With Quote
View Public Profile
 
Old 01-01-2007, 10:39 AM Re: Form Problem
larryweiss's Avatar
Super Talker

Posts: 117
Location: NEW YORK
Trades: 0
Kudos Logic Ali

QED

Thank you
__________________
Larry Weiss


Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
| |
Please login or register to view this content. Registration is FREE
larryweiss is offline
Reply With Quote
View Public Profile Visit larryweiss's homepage!
 
Reply     « Reply to Form Problem
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36807 seconds with 12 queries