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

how to read form label?


Is it possible to read "label" from form-field?

<label for="product1">bread</label>
<input id="product1" name="product1" type="text" size="3">

number comes with $_GET[product1];

but how do I read the "bread"?
Or is there a way to print the "name" to form?
like:
<input name="bread" type="text" size="3">
The point would be to have same single text visible on the page, and
returned by form.

Jul 17 '05 #1
4 9279
You dont.

have an array or other way of matching the product numbers to a type;

eg:

$_MY_PRODUCTS[1] = "Bread";
$_MY_PRODUCTS[2] = "Soup";

echo $_MY_PRODUCTS[ $_GET['product1'] ];

- Ali

"Mikko" <ei******@invalid.net> wrote in message
news:so**************@read3.inet.fi...

Is it possible to read "label" from form-field?

<label for="product1">bread</label>
<input id="product1" name="product1" type="text" size="3">

number comes with $_GET[product1];

but how do I read the "bread"?
Or is there a way to print the "name" to form?
like:
<input name="bread" type="text" size="3">
The point would be to have same single text visible on the page, and
returned by form.


Jul 17 '05 #2
Mikko wrote:
Is it possible to read "label" from form-field?

<label for="product1">bread</label>
<input id="product1" name="product1" type="text" size="3">
Not from PHP, you probably can do it from Javascript. Remember, PHP
runs on the server and has no knowledge of what anything looks like on
the screen or the code that displayed it. It just knows of information
that the web servers obtain from then browsers.
number comes with $_GET[product1];

but how do I read the "bread"?
Or is there a way to print the "name" to form?
like:
<input name="bread" type="text" size="3">
The point would be to have same single text visible on the page, and
returned by form.


You could use hidden fields for this:
<input name="product_name" type=hidden value="bread">

Or you could use an array for the name:
<input id="product1" name="product1[bread]" type="text" size="3">

And reference it by $_GET['product1']['bread']

It depends on what you are trying to do.

Ken

Jul 17 '05 #3
Ken Robinson kirjoitti:
Mikko wrote:
Is it possible to read "label" from form-field?

<label for="product1">bread</label>
<input id="product1" name="product1" type="text" size="3">

Not from PHP, you probably can do it from Javascript. Remember, PHP
runs on the server and has no knowledge of what anything looks like on
the screen or the code that displayed it. It just knows of information
that the web servers obtain from then browsers.
number comes with $_GET[product1];

but how do I read the "bread"?
Or is there a way to print the "name" to form?
like:
<input name="bread" type="text" size="3">
The point would be to have same single text visible on the page, and
returned by form.

You could use hidden fields for this:
<input name="product_name" type=hidden value="bread">

Or you could use an array for the name:
<input id="product1" name="product1[bread]" type="text" size="3">

And reference it by $_GET['product1']['bread']

It depends on what you are trying to do.

Ken


The meaning would be to have only one field, that can be modified easily
with Contribute.

So if updater wants to change "bread" in form to "puppet" the text in
page would change from bread to puppet. And the text returned by PHP
would change from
bread: 3
to
puppet: 3
(3 is from textfield in the form)

I would make that 1 entry as editable area by dreamweaver. So user could
update hes "store" himself, without needing to know about PHP or
field-names.

If he just changes the text, the php will still return something like
field1: 3, unless I can read the new text "puppet".

Jul 17 '05 #4
Below is a complete example document. It's strung together and not
organized like a real implementation should be, but shows you a way to
grab an associated label for an element and tack on a new hidden form
element to pass it along as though it was there all along.

Watch out for line wrapping.

J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com

------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>

<script language="JavaScript">
<!--
function submit_labels(){
//Gather information from the form and the element in question
//A more abstract version of this function should really be used where the
//form is submitted and all labels synced up with matching hidden values.
$form = document.getElementById("products");
$product = document.getElementById("product1");
$label_id = "label_" + $product.id;
$label = document.getElementById($label_id);
$label_value = $label.innerHTML;
//Take our gathered info and append a hidden element to the form for the
label.
var $new_element = document.createElement("<input>");
$new_element.setAttribute('type', 'hidden');
$new_element.setAttribute('name', $label_id);
$new_element.setAttribute('value', $label_value);
$form.appendChild($new_element);
return true;
}
//-->
</script>
</head>

<body>
<form id ="products" name="products"
action="http://www.phpgeek.com/util/formdump.php" method="get"
onsubmit="submit_labels();">

<label for="product1" id="label_product1">bread</label>
<input id="product1" name="product1" type="text" size="3">
<input type="submit">
</form>

</body>
</html>
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Altland | last post by:
Here is my basic problem. I have a form that executes a cpu instensive algorithm occupying the first thread. When the algorithm is executed another form pops up telling the user the progress that...
20
by: Brian | last post by:
I'm wondering what the group thinks is the best way to display the <label> element. The default rendering in Moz and MSIE/Win (probably others, too) only changes the mouse cursor (that's a strange...
3
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
1
by: monuindia | last post by:
HI, It may be a very elementry question, but I need to know that how can I get text of a label.
1
by: kfeller | last post by:
I've designed a Web Form that has a label control that I dynamically populate. I'm having an issue with this label control "over-writing" a table below it when I reshape the browser window or when...
2
by: Steve | last post by:
Hello, If I instantiate a class object from a form I would like to be able to write to a label on the calling form something like "hello from class object" from within a subroutine inside...
2
by: Joneleth | last post by:
Hi, sorry for that kind of a silly question, but j just got crazy finding a way to display a transparent label with a SIMPLE white border on a form with a dark backgrond color. I'd like to...
3
by: michaelstonecroft | last post by:
I have a System.Windows.Forms.Label obj. How can I copy/paste the text in the label during run time. The TextBox obj has the context menu by default. Can I have the same for Label? Thanks for the...
8
fayazmd
by: fayazmd | last post by:
Hi, I am stuck with a problem on labels. I have 30 labels on my from. And from one method i am returning a value, based on it i have to make one label as invisible. I took switch - case, but i...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.