Page 1 of 1
using value of select in the same page using GET method
Posted: Wed Feb 18, 2004 1:27 am
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
Posted: Wed Feb 18, 2004 7:19 am
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();
}
}
}
}
}
}
Posted: Wed Feb 18, 2004 7:37 am
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.
Posted: Wed Feb 18, 2004 7:48 am
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.
Posted: Wed Feb 18, 2004 8:27 am
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) {
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>");
}
echo("</select></form>");
This works if the page contents changes according to the selections.
Hope it helps