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

Form submission dependent on option selected

Hello,
I need to change the "name" part of the <input> of a form accordingly to an option selected from a dropdown.
Please refer to the code to understand what I mean.
The form is something like this, with a submit onchange
Expand|Select|Wrap|Line Numbers
  1. <form id="myform" method="a_method" action="an_action">
  2.     <select class="field" name="name_of_select" onchange="$('myform').submit();"
  3.     <option value="1">choise1</option>
  4.     <option value="2">choise2</option>
  5.     </select>
  6.  
  7. <input type="hidden" name="this_name_changes_when_option_selected_changes">
  8. </form>
  9.  
I'm not a programmer but I'm willing to learn as I need to make it work, but please explain things to me in a human understandable way:)
Thanks a lot.
mass
Mar 2 '13 #1
5 1545
Rabbit
12,516 Expert Mod 8TB
I don't understand why you need to change the name of the input when you're passing the value of the select anyways?
Mar 3 '13 #2
Hello.
I should'have explained better my goal but I didn't want to make the question too long.
Anyways..

Jessica, on 03 Mar 2013 - 00:15, said:
I think you need to explain what your overall goal is, because that sounds like a really weird thing to do.

Hello.
I have a CMS that can be customized throught template changes, the form I want to modify in fact is part of a template (smarty).

The "Original" code is something like this:
Expand|Select|Wrap|Line Numbers
  1. <form action="" id="zip" method="post">
  2.         <select class="field" name="set_zip_filter_distance" onchange="$('zip').submit()">
  3.             <option value="">Distance</option>
  4.             <option value="1">1km</option>
  5.             <option value="5">5km</option>
  6.             <option value="10">10km</option>
  7.             <option value="15">15km</option>
  8. .....and so on.....
  9.         </select>
  10.         <input type="hidden" name="submit_zip_filter"/>
  11.  
  12.         <!-- BUTTON1---<input type="submit" name="submit_zip_filter" value="submit" class="button" />
  13.          BUTTON2---<input type="submit" name="clear_zip_filter" value="reset" class="button" />-->
  14. </form>
  15.  
The parts in bold are the ones I added.
At the bottom of it you will notice 2 lines of code I commented out. They were 2 submit button I'm trying to get rid of, and that's the reason why I want to change the "name part" of the <input> line to change in accordance to the option selected.
The code above works but it only submits, I wanto to add 1 more option (<option value="RESET">RESET</option>) and cause the form to submit as if it was BUTTON2 if "RESET" is selected, and like BUTTON1 if another option is selected.

So far I tried among other things, this code
Expand|Select|Wrap|Line Numbers
  1.          <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  2. <script type="text/javascript">
  3.  
  4.     if $('#set_zip_filter_distance').change(function(){
  5.     $('#submit_line').attr('name', 'clear_zip_filter');
  6.     this.form.submit();
  7. }
  8.     else
  9.     {
  10.     this.form.submit();
  11.     });
  12.     </script>
  13.  
...but it doesn't work:(

Maybe someone experienced can help me?
Thanks a lot.
mass
Mar 3 '13 #3
Rabbit
12,516 Expert Mod 8TB
I still don't see the need to change the name of the hidden input. Whatever your end goal is, you can accomplish it without having to do this. But you haven't explained your end goal so I can't offer any advice on that.
Mar 3 '13 #4
My goal is to get rid of the 2 SUBMIT BUTTONS (those that are at the bottom of the script) and submit the form automatically on change of option selected.

This is what the code looks like without my modifications:

Expand|Select|Wrap|Line Numbers
  1. <form action="" method="post">
  2.         <select class="field" name="set_zip_filter_distance">
  3.             <option value="">Distance</option>
  4.             <option value="1">1km</option>
  5.             <option value="5">5km</option>
  6.             <option value="10">10km</option>
  7.             <option value="15">15km</option>
  8. .....and so on.....
  9.         </select>
  10.         <input type="submit" name="submit_zip_filter" value="submit" class="button" />
  11.         <input type="submit" name="clear_zip_filter" value="reset" class="button" />
  12. </form>
  13.  
Numerical options should "emulate" BUTTON NUMBER1, then I want to add a new option (something like <option value="RESET">RESET</option>) and use it to emulate the BUTTON NUMBER 2.
Thanks.
mass
Mar 3 '13 #5
Rabbit
12,516 Expert Mod 8TB
You can get rid of he buttons without having to change the name of an input.

You still haven't explained your end goal, you keep explaining what you're trying to do to reach the goal. But we still have no idea what that goal is.
Mar 4 '13 #6

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

Similar topics

4
by: Ram Raju | last post by:
Hi All, I am displaying few values in a List box. I would like to put first item as selected by default. i.e <option value="some value" selected>Name</option> Here is my code. <SELECT...
13
by: Nathaniel Maier | last post by:
Hi. How can I send form results to an email address based on what the user selects? e.g. not to the same address all the time, and not to all addresses, but to the one that the user selects. How...
4
by: Jeff Anderson | last post by:
Is there a style for a select option's "selected" color? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1...
1
by: Jonathan LaRosa | last post by:
Anyone know how to do this with javascript? I'm trying to avoid creating two different forms because then changes become that much harder to manage. Thanks in advance . . . ~ Jon LaRosa jlarosa...
2
by: Targa | last post by:
I have a select box with about 5 options. I need to have one of the options, when selected, display a second select box. The second select box is populated by a database and needs to be preloaded...
15
by: sam | last post by:
Hi, I have a bound dropdownlist with an event handler OnSelectedIndexChanged. If I select a value I'm redirected to another page. I come back using the browser's back button, and the option is...
4
by: markus.rietzler | last post by:
onChange() is working very well, when an option is choosen the first time. how can i detect when the user clicks and choose the same option again? this code works with IE 6.x. you can click the...
1
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the...
2
by: idontknow | last post by:
I have the following code : $form = "<head><title>:::Subjects:::</title></head> <script src='ajax_files/prototype.js'></script> <script src='ajax_files/getSecond.js'></script> <body>...
21
jinalpatel
by: jinalpatel | last post by:
I have three option buttons (1 option group): construction projects, non construction projects and aquisition projects. I have created a form with more than 35 data entry fields for each of this...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.