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

javascript not passing variable back to PHP

TIA for your help!

I have a page (code snip below) named "browse" which has a table in it with
rows like this:

2003 1500 Silverado pickup red 51,024 $19,995 Details

---------

each row of the table has a hidden id number which is to be passed on to the
next page when the user clicks on "Details" or any other item in the row.

In the code snip below is the javascript that processes the submit when
"Details" is clicked as well as the relevant table code.

When the subsequent page, "details.php" is loaded the following two lines
are executed:
$id = $_REQUEST['d'];
$ids = $_REQUEST['ids'];

In php.ini "register_globals" is off.

The problem is: Both ['d'] and ['ids] appear to be recognized but, $id
returns the correct value of "8", while $ids is "" instead of "'2615631'"

What I don't understand is why one works and the other doesn't.
Could someone explain the difference? I've tried some of the tips given for
using extract without any success.

Thanks
Marty

<html>
<head>
<link href="general.css" rel="stylesheet" type="text/css">

<script language="Javascript">
var marked_row = new Array;
function getDetails(obj)
{ theIDField = eval('document.browse.id'+obj);
theIDField.checked = "true";
document.browse.submit();
return true;
}
</script>

--snipped other code not relevant(I think)

<form method=post name=browse action=details.php><input type=hidden name=d
value="8">
<tr>
<td colspan=9><font color=black>Click Column Headings To
Sort.</font></td>
</tr>
<tr bgcolor=#D93540>
<td colspan=9><p class=bigheading><font
color=#FFFFFF>Chevrolet</font></p></td>
</tr>
<tr>
<td colspan=9><br></td>
</tr>
<tr bgcolor=#eeeeee id=0 onmouseover="highlight(this);"
onmouseout="unhighlight(this);">
<td valign=top><font color=black><input type=checkbox id=id2615631
name=ids[] value="2615631"></font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>2003</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>1500 SILVERADO</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>PICKUP</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>RED</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>51,024</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>$19,995</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black></font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>
<a href=# onClick="getDetails('2615631'); return
true;">Details</a></font></td>
</tr>

<tr bgcolor=#ffffff id=1 onmouseover="highlight(this);"
onmouseout="unhighlight(this);">
<td valign=top><font color=black><input type=checkbox id=id2615581
name=ids[] value="2615581"></font></td>
<td valign=top onClick="getDetails('2615581'); return true;"><font
color=black>2003</font></td><td valign=top

--snipped-repeat entries for multiple lines in table


Dec 21 '05 #1
1 1709
Marty Meyers wrote:
TIA for your help!

I have a page (code snip below) named "browse" which has a table in it
with rows like this:

2003 1500 Silverado pickup red 51,024 $19,995 Details

---------

each row of the table has a hidden id number which is to be passed on to
the
next page when the user clicks on "Details" or any other item in the row.

In the code snip below is the javascript that processes the submit when
"Details" is clicked as well as the relevant table code.

When the subsequent page, "details.php" is loaded the following two lines
are executed:
$id = $_REQUEST['d'];
$ids = $_REQUEST['ids'];

In php.ini "register_globals" is off.

The problem is: Both ['d'] and ['ids] appear to be recognized but, $id
returns the correct value of "8", while $ids is "" instead of "'2615631'"
To debug, start on the receiving page with:

<pre>
<? print_r($_POST); ?>
</pre>

or $_GET is you send via URL.

You will probably see that ids is not sent at all or empty.


What I don't understand is why one works and the other doesn't.
Could someone explain the difference? I've tried some of the tips given
for using extract without any success.

Thanks
Marty

<html>
<head>
<link href="general.css" rel="stylesheet" type="text/css">

<script language="Javascript">
var marked_row = new Array;
function getDetails(obj)
{ theIDField = eval('document.browse.id'+obj);
This is bad.
Have a look at document.getElementById('<ID HERE>');
It is the prefered way of getting elements.

theIDField.checked = "true";
I would prefer true instead of the string "true";
Unsure if this could be the cause of troubles.

document.browse.submit();
return true;
}
</script>

--snipped other code not relevant(I think)

<form method=post name=browse action=details.php><input type=hidden name=d
value="8">
Please be less sloppy, for your own good.
If you use name/value pairs, be sure you add the values as string.
Now you sometimes do, sometimes dont.

This is better:
<form method="post" name="browse" action="details.php">
<input type=hidden name="d" value="8">

So you are sending "d" with value "8".
You can retrieve it in detais.php as:
$received_d = $_POST["d"];

<tr>
<td colspan=9><font color=black>Click Column Headings To
Sort.</font></td>
</tr>
<tr bgcolor=#D93540>
<td colspan=9><p class=bigheading><font
color=#FFFFFF>Chevrolet</font></p></td>
</tr>
<tr>
<td colspan=9><br></td>
</tr>
<tr bgcolor=#eeeeee id=0 onmouseover="highlight(this);"
onmouseout="unhighlight(this);">
<td valign=top><font color=black><input type=checkbox id=id2615631
name=ids[] value="2615631"></font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>2003</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>1500 SILVERADO</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>PICKUP</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>RED</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>51,024</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>$19,995</font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black></font></td>
<td valign=top onClick="getDetails('2615631'); return true;"><font
color=black>

Well, you send a string to getDetails, the same string in all cases.

But in your getDetails you receive it named as 'obj'.
Why do you confuse yourself so much with bad names?
It is not an Object, it is a string.

What you should do is this (if I understand you right):

You want the value '2615631' send to the receiving script if somebody hits
the td, ok?

So just add to your form:
<input type="hidden" name="whatever_ids?" value="NA">

replace whatever_ids? with a good name of course.

ANd in your getdetails function:
getDetails(someString){
document.forms["browse"]["whatever_ids?"].value=someString;
document.forms["browse"]submit();

}

Regards,
Erwin Moller

PS: Debugging starts with:
1) in receiving script print the posting with pre and print_r()
2) in JS: use alert() to check your values.

<a href=# onClick="getDetails('2615631'); return
true;">Details</a></font></td>
</tr>

<tr bgcolor=#ffffff id=1 onmouseover="highlight(this);"
onmouseout="unhighlight(this);">
<td valign=top><font color=black><input type=checkbox id=id2615581
name=ids[] value="2615581"></font></td>
<td valign=top onClick="getDetails('2615581'); return true;"><font
color=black>2003</font></td><td valign=top

--snipped-repeat entries for multiple lines in table


Dec 22 '05 #2

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

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.