passing field value to a php page

X

Xerxes

Hi,
I am trying to pass the value of a field to a PHP file like this:

<input type="hidden" name="field1" id="field1" value="123">
<input type="hidden" name="field2" id="field2" value="456">

<a href =
"test.php?c1=document.getElementById('field1').value&c2=document.getElementById('field2').value
<img src="add.gif" border="0"></a>

In test.php, when I do:

c1=$_GET['c1'] ;
echo c1;

I get:

c1 = document.getElementById(\'field1\').
 
T

Thomas 'PointedEars' Lahn

Xerxes said:
I am trying to pass the value of a field to a PHP file like this:

<input type="hidden" name="field1" id="field1" value="123">
<input type="hidden" name="field2" id="field2" value="456">

<a href =
"test.php?c1=document.getElementById('field1').value&c2=document.getElementById('field2').value
<img src="add.gif" border="0"></a>

In test.php, when I do:

c1=$_GET['c1'] ;
echo c1;

I get:

c1 = document.getElementById(\'field1\').

Of course. It is rather astounding that you get anything at all, since
the attribute value is not Valid (it has not been properly delimited.
The value of the `href' attribute is specified to be URI reference.
Script data is not evaluated in URIs references automatically. However,
you do not need any script code or IDs here:

<form action="test.php">
<div>
<input type="hidden" name="c1" value="123">
<input type="hidden" name="c2" value="456">
<button><img src="add.gif" alt="Add" border="0"></button>
</div>
</form>

You should be aware that this works in HTML 4-compliant user agents only
because of the `button' element.

<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-BUTTON>


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top