473,549 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attaching second value to a form submit button.

160 New Member
I only have a basic understanding of html. What i want to do is have a group of form submit buttons within the same form but i need each button to pass on two values unique to it's self (one is hidden). If i use a <input type="hidden"
Oct 28 '07 #1
5 9571
69 New Member
I only have a basic understanding of html. What i want to do is have a group of form submit buttons within the same form but i need each button to pass on two values unique to it's self (one is hidden). If i use a <input type="hidden"
Yes, you can have multiple submit buttons on a single form, however if you have a hidden field within the form, each submit button is going to submit that field. If each button needs to pass a certain variable, you can assign the value of the variable to the button instead of a hidden field, that way each button will submit a different value. I once did something like this just for fun, where I used submit buttons as a menu to navigate a site. The code I used had the buttons with different values of each button would determine what content to load. You will probably want to keep each value the same and give each button a different name. Then using php, you can check which button was clicked.

Form would be something like
Expand|Select|Wrap|Line Numbers
  2.  <form method="post" action="index.php">
  3.  <input name="val1" type="submit" value="submit" />
  4.  <input name="val2" type="submit" value="submit" />
  5.  <input name="val3" type="submit" value="submit" />
  6.  <input name="val4" type="submit" value="submit" />
  7.           </form>
and then using php to determine the button that was clicked would be something like...
Expand|Select|Wrap|Line Numbers
  1. if($_POST['val1']) {
  2. ///code for val1
  3. }
Good luck and hope this helps!
Oct 28 '07 #2
160 New Member
Thanks! Yes this is what i would like to do but each of the submit buttons needs to pass on two values. I suppose i could glue the two values into a string then explode them on the new page.

I don't think the below code is valid but it represents the idea i'm looking for...

<form method="post" action="index.p hp">
<input name="name" type="submit" value1="$val1" value2="$val2"/>
<input name="name" type="submit" value1="$val3" value2="$val4"/>

The only reason they need to be in the same form is for looks, this the only way i can figure out to get buttons to sit side by side without creating multiple <td>'s to hold each. I want them side by side and in the same <td> so that they wrap and build up multiple rows of buttons on the screen instead of one column. Maybe i can get around this by abandoning tables and using CSS?

The buttons are created in a 'while' loop so the number will vary. I need to keep them with the same name so that i don't have redundant php code which has to look for the max number of possible buttons every time... hmmm unless i put that in a loop which would count up through buttons until it found the one that was submitted... it would just be so much easier if there was a way to submit two values for each button in the form....
Oct 28 '07 #3
69 New Member
The buttons within the same <td> should display in a row. The code I gave you displays them in a row in IE and Firefox. Using CSS on top of that you can make the buttons look and behave in many different ways. The next thing is that the button will say what is in the value field. If this is ok, then you could assign the different values and probably be ok with it, but both values would have to be under one 'value' tag. You can't have two value tags in the same button. If this doesn't work, then you might have to assign each button a different name. Maybe a combination of different 'name' and 'value' attributes will get you what you need, or like you mentioned, use the explode() function to get each value you need. I am not sure on the look and exactly what your doing, but with a combination of these ideas, it sounds like you can get it.

As far as your second loop idea is concerned, if you go that route I would look into a switch statement within php. This might be helpful in writing one loop that will handle the form correctly depending on which button is pushed.

Good Luck!
Oct 28 '07 #4
160 New Member
Thanks for your help lumpy! I think i'll use a string and explode it on the other end.. it seems to be the most flexible and has the least redundancy.

Oct 28 '07 #5
69 New Member
Thanks for your help lumpy! I think i'll use a string and explode it on the other end.. it seems to be the most flexible and has the least redundancy.

No Problem. Glad I was able to be of some help. :D

Post back if you have any other questions.
Oct 28 '07 #6

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

Similar topics

by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p align="center"><input class="button" type="button" onClick="location='draftedStory.asp';" value="Click to complete the drafted story"></p> <p align="center">...
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
by: r0adhog | last post by:
I have a very simple form: <html> <head> </head> <body> <% function ValForm() if len(document.form.newapp.all("AccessCode").Value) = 4 then document.form.newapp.submit()
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag....
by: Ale K. | last post by:
What's the best way to make a form return a value.... i want to try to avoid using module variables for doing this... Thanks. Alex.
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript Web GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and clicks again, which creates duplicate records. So I am trying to disable the button as soon as it is clicked, and as soon as it's done,...
by: remya1000 | last post by:
i'm using ASP with MSAccess as database. i have two buttons and two textbox in my page. when i press my first button (First month) i need to display the current month in one textbox and last one months date in another textbox. and while pressing the second button (submit) i need to display the date displayed in the textbox as itself and the...
by: satish2112 | last post by:
Hi, I have a text-area which contains values from mysql database and 2 buttons, Edit and Update. When I click on the Edit button, I can edit the text-area (initially non-editable). After this, if I click on the Update button, the values in the text-area must be updated in the mysql database. I am storing the values of the text-area in a...
by: huseyin | last post by:
Hello, I have two forms written mainly in php. Here how it functions currently: - First form has two submit buttons. - First submit button is a search button that submits a value of an input field that activates a database query and get the result - I control the length of the entered text with Java Script in the input field and activate...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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...
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...
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...
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...
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...
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...
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...

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.