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

Attaching second value to a form submit button.

bugboy
160 100+
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 9544
Lumpy
69
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
  1.  
  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>
  8.  
  9.  
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. }
  4.  
Good luck and hope this helps!
Oct 28 '07 #2
bugboy
160 100+
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...

[HTML]
<form method="post" action="index.php">
<input name="name" type="submit" value1="$val1" value2="$val2"/>
<input name="name" type="submit" value1="$val3" value2="$val4"/>
</form>[/HTML]

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?

more:
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
Lumpy
69
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
bugboy
160 100+
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.

BugBoy
Oct 28 '07 #5
Lumpy
69
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.

BugBoy
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

1
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...
24
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?
7
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()
12
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...
9
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.
6
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...
3
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...
1
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,...
5
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.