[SOLVED] how does this translate??

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

Post Reply
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

how does this translate??

Post by fresh »

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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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..
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

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.. ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'd have a parse error.. several times over..

~ is an operator, you need to quote the strings.
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

:oops: oops.. so if I add the quotes then that will change the value of the input box??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'd have to echo out $c and $d respectively back into the form elements..
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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..
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

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... »

<html> and Javascript is hybrid script, non?
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

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 :)
Post Reply