• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

php to javascript

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67502
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or simply:

<input type"text" value="${somePHPthing}"/>
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)";

}
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fixed it you don't use the quotes. thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No more fooling around. Read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic