I'm passing a variable ID to a javascript function from a row of HTML
data, like this:
echo "<tr onClick=\"submitSiteID('$siteID[$idx]');\" >";
My function writes the value to a box on my form:
function submitSiteID(siteValue) {
document.forms['formSitesGrid'].elements['passedValue'].value = siteValue;
document.forms['formSitesGrid'].submit();
}
The thing is, the only way I can figure to pass my variable to the
destination page is to put it in a hidden text box on my form, then
submit the form with this function. I need to put this bogus table in my
form to make it work:
echo "<table>";
echo "<tr>";
echo "<td>";
echo "<input type='hidden' name='passedValue' />";
echo "</td>";
echo "</tr>";
echo "</table>";
This all works great, but it can't be the most elegant way to do it. Can
anyone tell me how to pass the siteValue variable to my destination page
using GET/POST without messing around with this extra code on my page?
I'm trying to stay away from cookies (my users hate them).
Thanks for any help.
Hi Arch,
> I'm passing a variable ID to a javascript function from a row of HTML
> data, like this:
>
> echo "<tr onClick=\"submitSiteID('$siteID[$idx]');\" >";
>
Bah, That is hard to read and understand.
Why don't you jump out of PHP and produce your HTML in a readable way?
The escaping is very confusing: Try writing regular expression like that
in JavaScript. ;-)
So instead of:
echo "<tr onClick=\"submitSiteID('$siteID[$idx]');\" >";
I strongly suggest:
?>
<tr onClick="submitSiteID('<?php echo $siteID[$idx]; ?>');" >
<?php
That way you view your javascript as in 'view source'.
But that doesn't relate to your problem, I know.
> My function writes the value to a box on my form:
box? textelement? hidden element? What is a box?
>
> function submitSiteID(siteValue) {
> document.forms['formSitesGrid'].elements['passedValue'].value =
> siteValue;
> document.forms['formSitesGrid'].submit();
> }
OK, So if the visitor hits a tr with the mouse, the forms gets submitted?
That is a surprising userinterface.
But I don't know your requirements of course.
>
> The thing is, the only way I can figure to pass my variable to the
> destination page is to put it in a hidden text box on my form, then
> submit the form with this function.
That is one way (and a good way).
(Of course, your website will only work for those with JavaScript enabled.)
> I need to put this bogus table in my
> form to make it work:
>
> echo "<table>";
> echo "<tr>";
> echo "<td>";
> echo "<input type='hidden' name='passedValue' />";
> echo "</td>";
> echo "</tr>";
> echo "</table>";
I do not understand why you need that bogus table.
Actually: you don't need it at all.
Why not simply put the hidden form element right under your form
declaration? (Of course without the table)
>
> This all works great, but it can't be the most elegant way to do it. Can
> anyone tell me how to pass the siteValue variable to my destination page
> using GET/POST without messing around with this extra code on my page?
> I'm trying to stay away from cookies (my users hate them).
What about hyperlinks?
<a href="whatever1.php?id=23">Hi</a>
<a href="whatever1.php?id=27">Hi again</a>
Then use $_GET["id"] to retrieve the passed value.
>
> Thanks for any help.
I could think a many other answers too: your questions is quite vague in
my opinion. If you need a better, more to the point, answer, ask a
clearer question.
FOr example: What do you mean by "without messing around with this extra
code on my page"? JavaScript code? PHP?
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
I'm not sure why you even need javascript in this case. If you want the
value displayed on the page, you can just display it. If you want the
user to be able to change the value, put it in the appropriate html field.
If all you want to do is remember the value from one page to the next,
then use the session. See http://www.php.net/manual/en/book.session.php
for more info.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
Grateful noob :|
Thanks-
Grateful noob :|