using value of select in the same page using GET method

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
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

using value of select in the same page using GET method

Post by softsolvers »

hello friends
i want to use the dropdown menu in my php page,and like to use the value selected in the same page where i have the select menu(drop down menu).Can u suggest me something or send me the snapshot of the code
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Two thoughts both with javascript:

1. Reload the page when selection changes and use the value
2. On change event for selection changes the HTML labelled with an ID.

Example Javascript function (Need to test which browsers work):

Code: Select all

function changeElemContent(elementId,content) {
  if(document.implementation &&
    document.implementation.hasFeature &&
    document.implementation.hasFeature('Range','2.0')) {

    // Can use ranges (Netscape 6+)
    node = document.getElementById(elementId);
    var newRange = document.createRange();
    newRange.selectNodeContents(node);
    newRange.deleteContents();
    var newHTML = newRange.createContextualFragment(content);
    node.appendChild(newHTML);

  } else {
    if(document.getElementById) {
      // Process using inner HTML (Explorer 5&6)
      document.getElementById(elementId).innerHTML=content;
    } else {
      // Other generic tries to match other browsers. Does not always work (e.g Netscape 4)
      if (document.all) {
        document.allїelementId].innerHTML=content;
      } else {
        if(document.layers) {
          with(document.layersїelementId].document) {
            open();
            write(content);
            close();
          }
        }
      }
    }
  }
}
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

Post by softsolvers »

hello friend
thanks for your time ,i think i need to explain my need.
what i need is
1.when selecting the value from the drop down button ,using that value to make a new drop down menu.
for this i need that which value had choosen and then i will make the new drop down through code.
i am showing you the code of my approach.
my main objective is to first grasp the value which user has selected, i agree that this will be done in javascript only.but can i take the valuee in the java script function in the php code which is written in the same form.
i think i am quite complex but plz. do help me bcoz i am very tensionize now.
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

Post by softsolvers »

hello friend
thanks for your time ,i think i need to explain my need.
what i need is
1.when selecting the value from the drop down button ,using that value to make a new drop down menu.
for this i need that which value had choosen and then i will make the new drop down through code.
i am showing you the code of my approach.
my main objective is to first grasp the value which user has selected, i agree that this will be done in javascript only.but can i take the valuee in the java script function in the php code which is written in the same form.
i think i am quite complex but plz. do help me bcoz i am very tensionize now.
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Ok sounds as though you could approach this by reloading the form each time you change something. (simplified example to provide starting point not fully workable code)

Code: Select all

echo ("<form name=myform action=dummy.php>
<select name=formval1 onchange="javascript:document.myform.submit()">
  <option val=1>abc</option>
  <option val=2>def</option>
</select>
<select name=formval2>");

switch ($formval1) &#123;
  case "1":
      echo("<select name=formval2>
<option>abc 1</option>
<option>abc 2</option>");
      break;
  case "2":
      echo("
<option>abc 1</option>
<option>abc 2</option> ");
  default:
     echo("<option>Unknown</option>");
&#125;
echo("</select></form>");
This works if the page contents changes according to the selections.

Hope it helps
Post Reply