By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
461,974 Members | 541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 461,974 IT Pros & Developers. It's quick & easy.

How to use option name as value using javascript?

P: 4

I came across this forum looking for an answer and by reading I found that it seemed really supportive forum. I hope I am posing to correct tread :-(

I need to use the option name as value to pass on as well as the value it self.

I have a select statement. Because I am using calculations for the freight for each state, in the Value I have the ($) amounts. This is required not only for final freight calculation depending on which state is selected but also I need to know which amount they have selected.

Unfortunately I am no expert in in java scripts. What I also need to show on my confirmation page is the actual name of the State. At the moment (understandable) not showing as options can't have two values.

Can anyone hand over a plate please ?

Seriously I do need some thing I can copy and paste to make it work. So far I have build the form my self...and here it is in case you want to peak

Expand|Select|Wrap|Line Numbers
  1. <span class="left">
  2.   <input id="suburb" name="suburb" type="text" class="field text addr" value="" tabindex="10"  />
  3.   <label for="suburb">City</label>
  4.   </span>
  7.   <span class="right">
  8.   <select name="freight_fee_($)" class="field select medium" id="freight_fee_($)"  tabindex="14" >
  9.     <option value="9">Queensland</option>
  10.     <option value="12">New South Wales</option>
  11.     <option value="12">ACT</option>
  12.     <option value="13">Victoria</option>
  13.     <option value="14">South Australia</option>
  14.     <option value="16">Western Australia</option>
  15.     <option value="15">Northern Territory</option>
  16.     <option value="15">Tasmania</option>
  17.   </select>
  21.     <label for="canvas_size">State / Region</label>
  22.   </span>
and the calculation done at the bottom of the page like so -

Expand|Select|Wrap|Line Numbers
  1. <input name="button" type="button" id="button" onclick="KW_calcForm('Total',100,2,'(','#qty_480mmx350mm_ordered','*','#total_amount_for_ 480mmx350mm_ordered',')','+','(','#qty_480mmx480mm_ordered','*','#total_amount_for_ 480mmx480mm_ordered',')','+','(','#qty_780mmx480mm_ordered','*','#total_amount_for_ 780mmx480mm_ordered',')','+','#freight_fee_($)')" value="Total" /> 
  3. <input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="Next" />
There is also some java script that does the calculation on the top of the page.

In my posted form I want to be able to request the name of the selected item (eg Queensland) and the value.

As you can see here is my confirmation page


Confirm Title: Photo On Canvas Order

Total Amount For 480mmx350mm Ordered:85
Qty 480mmx350mm Ordered: 1
Qty 480mmx480mm Ordered: 0
Qty 780mmx480mm Ordered: 0
First Name: test
Surname: me
Address: My home address
Suburb: Bondi
State : << I also want to display the state they have chosen (eg Queensland) >>

Freight Fee ($): 12 >>>>> this is the value from the above option fields
Post Code: 2000
Total: 94.00
Attachment: ist2_4469423-business-card-or-white-sign.jpg
Jul 20 '10 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
Since this is on the confirmation page, it's actually PHP code you should be looking at.

However, I can suggest 3 possible solutions:
1. Use JavaScript to set a hidden field to the state when an option is selected, but this depends on JavaScript to function.
2. Set the value of each option to something like "9|Queensland" which you can use to split on the confirmation page.
3. Probably the best idea would be to take the state name and use that to determine the freight fee on the server-side. If you depend on the value passed, someone could change 9 to 0 or something. Of course, you could still use JavaScript to give the user some idea of how much it would cost, but you don't depend on it.
Jul 20 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.