evault
asked on
how do I pass a java script variable back to the PHP Server
I am trying to edit a user in a database. I am using a Java Script to select the user and want to then pass the user name back to the server and be able to access it via PHP.
How do I do that?
I have everything in place except how to access the vaule I picked from the DB Grid using Java.
The code below properly displays the selected MySQL record's username. How do I get that information back to the server?
How do I do that?
I have everything in place except how to access the vaule I picked from the DB Grid using Java.
The code below properly displays the selected MySQL record's username. How do I get that information back to the server?
var Rw=DBG_Users.getFocusedRow();
// fetch the user name (Col2) of the selected record
var ThisUser=DBG_Users.getTableModel().getValue(2, Rw);
it is not clear to me what you want , but try one of the
1. Javascript redirection with get parameters
<script>
user=mike
window.location = "http://www.site.com/?action=info&user="+user ....
<script>
2. place a hidden field in your form , like "<input type='hidden' name='user'/>" and update the value via javascipt before do post
1. Javascript redirection with get parameters
<script>
user=mike
window.location = "http://www.site.com/?action=info&user="+user ....
<script>
2. place a hidden field in your form , like "<input type='hidden' name='user'/>" and update the value via javascipt before do post
evault,
Besided the 2 methods recommended above the only other I can think of is to use cookies. Javascript can't send it direct to PHP script but those 3 things are common between the languages/technologies and can be used to exchange info. If you want to use a cookie in either and need details then let me know.
Let me know if you have any questions or need more information.
b0lsc0tt
Besided the 2 methods recommended above the only other I can think of is to use cookies. Javascript can't send it direct to PHP script but those 3 things are common between the languages/technologies and can be used to exchange info. If you want to use a cookie in either and need details then let me know.
Let me know if you have any questions or need more information.
b0lsc0tt
ASKER
pesmerg: I tried doing that and get 'Error on page'
This is the Java Script exceuted when the button is clicked
document.getElementById('foo').value = 'thenewvalue';
this is the HTML code
?>
<form>
<input type="hidden" name="something" id="foo"/>
</form>
<?php
Let us see more of the html and Javascript (e.g. form, fields, script, button). Also click on the message of "error on page" and let us know the error and show us the code for that line.
bol
bol
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you for your assistance. I had already figured out the procedure by the time you had posted the answer.
eg:
<form name="form" action="yourphpfile.php" method="post">
<input type="hidden" name="ThisUser" value="">
</form>
Then:
<script>
document.getElementByName(
</script>