Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

php to javascript

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or simply:

<input type"text" value="${somePHPthing}"/>
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.]
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed it you don't use the quotes. thanks.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the $ for javascript variables?
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because they were php at one time but I changed it and didnot change the variable. it all works now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic