PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 30, 2004 1:30 am
hey, wondering how this Jscript would translate into PHP:
Code: Select all
function chk0(){
if(document.formsї0].a.value=="A") {
document.formsї0].a.value = "Apple";
} else {
return;
}}
function chk1() {
if(document.formsї0].b.value=="~") {
document.formsї0].b.value = "~apple";
} else {
return;
}}
Thanks in advance
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 1:35 am
Code: Select all
function chk0()
{
if(isset($_GET['a']) && $_GET['a'] == 'A') return 'Apple';
else return false;
}
function chk1()
{
if(isset($_GET['b']) && $_GET['b'] == '~') return '~apple';
else return false;
}
not a direct translation.. the code you posted is dynamically changing the value of a form element, which PHP cannot directly do without the data going to the server first..
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 30, 2004 1:49 am
so would I just go like this:
Code: Select all
$a = A
$b = ~
$ax = Apple
$bx = ~apple
$c = $_POST['a'];
$d = $_POST['b'];
if($c == $a) {
$c = $ax;
} elseif($d == $b) {
$d = $bx;
}}
would that work... I'm wanting to change the form field dynamically like you said, and this is my attempt at that..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 2:00 am
you'd have a parse error.. several times over..
~ is an operator, you need to quote the strings.
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 30, 2004 2:26 am
oops.. so if I add the quotes then that will change the value of the input box??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 2:30 am
you'd have to echo out $c and $d respectively back into the form elements..
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 30, 2004 2:47 am
oh i just got what you meant thanks
P.s. how do I call a PHP function from an HTML page??
ex:
Code: Select all
<?php
$a = "A";
$b = "Apple";
$c = $_POST['a'];
function chk0() {
if($c == $a) {
echo "<input type='text' name='a' value=".$b."; maxlenght=60 onkeyup='chk0()'>";
} else {
return false;
}}
function chk1() {
$d = "~";
$e = "~apple";
$f = $_POST['b'];
if($f == $d) {
echo "<input type='text' name='a' value=".$e."; maxlenght=60 onkeyup='chk1()'>";
} else {
return false;
}}
?>
will this work like this, It isn't seeming to work for me, but this seems logical.. hmm.. could someone show me how to properly call those 2 php functions, I can't find anyway to make this work right... thanks
Last edited by
fresh on Fri Jul 30, 2004 3:17 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 3:16 am
those calls will be to javascript, or the default scripting agent. The only way to communicate data to and from PHP is through submitting the data..
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 30, 2004 3:41 am
woo hoo, I got it working!! I feel good about this one, because I coded up a hybrid script, (my first one), and it works great.. thanks for the advice feyd
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Fri Jul 30, 2004 8:06 am
<html> and Javascript is hybrid script, non ?
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 30, 2004 6:11 pm
well, not really hybrid, but it is cool that I was able to tranlate a javascript function into PHP.. so to me it's kinda hybrid, because it utilises both PHP and Javascript, to process one event.. so that's why I said that