aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes php to javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "php to javascript" Watch "php to javascript" New topic
Author

php to javascript

Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I'm using some java script to get information from one page to another how do I pass the information found from the php to a java script function. here is the php I am getting information from a group of checkboxes. I need to string.split the information then place it in text boxes.
&?php
if (isset($_POST['Submit']))
{

foreach($_POST['checkboxform'] AS $checkboxform) ;
echo "$checkboxform &br /&";
}
?&
note repalced angle brackes with &
checkboxform is two peices of information.
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I figured out how to split the string but I have another question how do you input a variable into a textbox?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Can't you just directly take you php code and put the value into a textbox?

what you asked for is: document.formName.elementName.value = "blah";

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Or simply:

<input type"text" value="${somePHPthing}"/>


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Eric
I tried your way and it did not work. I'll try it again or I will try the other way. Thanks.
document.cart.Title.value = "$name"; does not work
$document_cart_Title_value = "$name";does not work this gives me the page without the information.


Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Both ideas do not work what I am getting now is the name of the variable insteadd of the value. Any ideas? the code below puts $($name) in text box.

function getValue()
{
document.cart.Title.value = "$($name)";

}
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Everything that needs to be processed by the P H P engine needs to be enclosed in <?p h p ?>. You don't seem to be doing that. You might try something like:

<input type='text' value='<?p h p $name ?>' />

or

function getValue()
{
document.cart.Title.value = "<?p h p $name ?>";
}

Why are you calling a get method and setting a value?

Either way, your question isn't real clear to me on what you are trying to do and this isn't really a Javascript issue. It's a PHP issue. And we are a Java site.

[I had to put spaces in p h p so I could post this. The spaces shouldn't be there.]


GenRocket - Experts at Building Test Data
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Sorry for being unclear. I got the PHP problem fixed. I am trying to put a variable in java script into a text box. When I try to do this all I get is the variable name in the test box.
document.cart.Title.value = "$(name)"; does not work
document.cart.Price.value = "$(cost)";
<input type="text" name="Title" value= "$(name)"/>
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Donna Bachner:
Sorry for being unclear. I got the PHP problem fixed. I am trying to put a variable in java script into a text box. When I try to do this all I get is the variable name in the test box.
document.cart.Title.value = "$(name)"; does not work
document.cart.Price.value = "$(cost)";
<input type="text" name="Title" value= "$(name)"/>


Well, lets start with something simpler..Does this work?

document.cart.Title.value = "Some Value I am entereing";

If that works, then in your example, what do you think $(name) and $(cost) should be?
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
When I type that in I get "Some Value I am entering" I added the "$(cost)" and got $(cost) it should be 45.00
var cost = 45.00;

document.cart.Price.value = "$(cost)" ; I get $(cost)
document.cart.Price.value = "$cost"; I get $cost
How else do you tell the editor it is a variable?
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I fixed it you don't use the quotes. thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Why are you using the $ for javascript variables?
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
because they were php at one time but I changed it and didnot change the variable. it all works now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: php to javascript