473,672 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form submission dependent on option selected

3 New Member
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 1556
Rabbit
12,516 Recognized Expert Moderator MVP
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
massimassi
3 New Member
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">R ESET</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 Recognized Expert Moderator MVP
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
massimassi
3 New Member
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">R ESET</option>) and use it to emulate the BUTTON NUMBER 2.
Thanks.
mass
Mar 3 '13 #5
Rabbit
12,516 Recognized Expert Moderator MVP
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
3197
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 size=15 id=select1 name=select1> <% do while not Rs.EOF %>
13
6213
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 can I refer to that? Thanks for the help. Nathaniel Maier email/MSNmsg: nmaier@columbus.rr.com AIM: OSUKid7
4
102929
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 <OPTION>Test 2 <OPTION>Test 3 <OPTION>Test 4
1
1480
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 at alumni dot brown dot edu I would like to create 2 links to a form that do the following: A) one link would open the form with one option of a drop down list selected
2
2590
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 so the page doesnt refresh. How can this be done? I guess could have the second select box displayed but disabled and it would become active once the option is selected on the first select box.
15
3812
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 still selected. So far so good. But the very weird thing is that if I look at the source code : <option selected="selected" value="13808">DataPage6</option> <option value="13805">DataPage5</option>
4
6460
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 same option again and again and the onChange()-event comes up. firefox will react on the onmousedown but the onChange is not executed. is there a way to detect selecting the same option again and again? <html>
1
5062
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 textbox(es) and the submit button showing until another option is selected. Also the data that's submitted is showing on the form page. Here's an example - I need the code below to do this: 1. I go to the page - I see a drop down box. 2. I...
2
2560
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> <form action='subjects.php' method='get' enctype='multipart/form-data'> <table width='394' border='1' align='center' cellpadding='5' cellspacing='5'> <tr> <td>Programe Name:</td>";
21
6561
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 options.ex.frmConstructionProjects,frmNonconstructionProj, frmAquisitionProjects When user selects an option fromm the options group it should open the respective subform. Private Sub optProject_Click() If Me.optProject.Value = 1 Then...
0
8945
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8847
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8643
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7476
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6255
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4242
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2094
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1839
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.