Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using onChange behavior

Community Beginner ,
Dec 10, 2012 Dec 10, 2012

Hi,

I am working in Dreamweaver 5.5 on a php file.

I have a variable $username = $_SESSION['MM_Username'] and another variable: $user_asking. I want to assign the value $username to $user_asking when a Select (List/Menu) is changed, using onChange Behavior. It is possible? Thank you!

TOPICS
Server side applications
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 11, 2012 Dec 11, 2012

On a sidenote, I doubt this possibility. PHP is server-side, Javascript is client-side. Unless you actually submit the form to PHP for processing and get a return value, I doubt if you can use the value within an onChange behavior.

Anyway, post your code in full so we can offer more suggestions.

-ST

Translate
LEGEND ,
Dec 11, 2012 Dec 11, 2012

Can we see your full code?

-ST

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 11, 2012 Dec 11, 2012

On a sidenote, I doubt this possibility. PHP is server-side, Javascript is client-side. Unless you actually submit the form to PHP for processing and get a return value, I doubt if you can use the value within an onChange behavior.

Anyway, post your code in full so we can offer more suggestions.

-ST

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2012 Dec 11, 2012

Hmmmmm...the script is pretty long already (almost 2000 lines) and to give you only that part is complicated. My question, simplified, is like this: what I have to write on Tag inspector-Behaviors-onChange in order (when the event appear) to assign a particular value to a variable?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 11, 2012 Dec 11, 2012

Like I said, I don't think it is possible to do this with your PHP and JS on the same page. JS needs to post the data back to PHP for processing which happens on pageload.

However, I'm moving this thread to Developing Server-side applications in DW for better responses.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 17, 2012 Dec 17, 2012

I agree. You would need to write some AJAX code on the page that communicates with a separate php file. The php file could send data back to your page without reloading it. I was just working on something very similar this morning.

Something like this might work for you...

On the page with the select element:

<script type="text/javascript">

function doSomethingOnServer(){

     if(window.XMLHttpRequest){

          //code for IE7+, Firefox, Chrome, Safari

          xmlhttp = new XMLHttpRequest();

     }

     else{

           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

     }

      xmlhttp.onreadystatechange = function(){

          if(xmlhttp.readyState == 4 && xmlhttp.status == 200){

               document.getElementById("my_paragraph").innerHTML = xmlhttp.responseText;

          }

     }

     xmlhttp.open("GET", "do-something.php, true);

     xmlhttp.send();

}

</script>

<select id = "my_select" onChange = "doSomethingOnServer()">...</select>

<p id="my_paragraph"></p>

On a separate php file named do-something.php:

<?php

     //do something

     $user_asking = $username;

     echo("Write out data that you want to sent back as responseText here. i.e., user asking = $user_asking");

?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 18, 2012 Dec 18, 2012

I was affraid that I will need something like this. Thank you very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2012 Dec 18, 2012
LATEST

Sudarshan and geotrice are correct, but what is not clear is what you are trying to accomplish - it's not making sense to me.  The server side script has already completed execution by the time the user is interacting with the list/menu, so what's the point of changing the value of a variable at that point? What do you plan to do with that value? What is the workflow after the user interacts with the list/menu?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines