/    Sign up×
Community /Pin to ProfileBookmark

Select Disabled and Post

Hi All:

I’m working on a site to manage employee data. In the employee data edit area I have four select menus loaded with employee ids in the value and the employee names in the text (Regional Manager, General Manager, Supervisor…etc). As it happens I need to disable these selects based on the user who logs in. This part is done.

The problem is, when I POST the form the SELECT menus which are disabled return no values.

Does anyone know a way to POST these values so that php can retrieve the data and process the request?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MaxHewittauthorSep 02.2004 — I've sort of worked it out, but I'd like a better solution if there is one.

I use the onclick event of the Submit button on the form to validate data and while validating data I have it enable the select items that are problematic. I really don't want to have to do this, but it seems it might be the only way.

Am I crazy?
Copy linkTweet thisAlerts:
@NogDogSep 02.2004 — May not be entirely clear on what your're doing, but maybe you could conditionally create a hidden field? For example:
[code=php]
if($some_condition)
{
# disable select
echo "<input type=hidden name=same_name_as_select value=some_value>";
}
[/code]

Or, what I've done is if a particular user is not allowed to change the select, then I make it so that the only option for that select is the one he's allowed:
[code=php]
echo "<select name=something>n";
if($some_condition)
{
echo "<option value=123>Default 123</option>n";
}
else
{
# construct full list of options
}
echo "</select>n";
[/code]
Copy linkTweet thisAlerts:
@MaxHewittauthorSep 02.2004 — I didn't want to break up the continuity of the page by using the hidden fields (I do this in my menu bar and it works quite well)

Anyone got any other cool ideas?
Copy linkTweet thisAlerts:
@crh3675Sep 03.2004 — This works in Mozilla, NS and Firefox. IE does not.

<i>
</i>&lt;script type="text/javascript"&gt;

var disablers=0;

function posLeft(eElement)
{
var nLeftPos = eElement.offsetLeft; <br/>
var eParElement = eElement.offsetParent; <br/>
while (eParElement != null)
{ <br/>
nLeftPos += eParElement.offsetLeft; <br/>
eParElement = eParElement.offsetParent; <br/>
}
return nLeftPos; <br/>
}

function posTop(eElement)
{
var nTopPos = eElement.offsetTop; <br/>
var eParElement = eElement.offsetParent; <br/>
while (eParElement != null)
{ <br/>
nTopPos += eParElement.offsetTop; <br/>
eParElement = eParElement.offsetParent; <br/>
}
return nTopPos; <br/>
}


function disableUse(obj){

<i> </i>var oTop=posTop(obj);
<i> </i>var oLeft=posLeft(obj);
<i> </i>var oWidth=obj.offsetWidth;
<i> </i>var oHeight=obj.offsetHeight;

<i> </i>var myDiv=document.createElement("DIV");
<i> </i>myDiv.id="disabler"+(disablers++);
<i> </i>myDiv.style.position="absolute";
<i> </i>myDiv.style.left=oLeft+"px";
<i> </i>myDiv.style.top=oTop+"px";
<i> </i>myDiv.style.width=oWidth+"px";
<i> </i>myDiv.style.height=oHeight+"px";
<i> </i>myDiv.style.backgroundColor="transparent";
<i> </i>myDiv.style.zIndex=200;
<i> </i>myDiv.setAttribute("title","This field is not editable.");
<i> </i>document.body.appendChild(myDiv);


}

&lt;/script&gt;

&lt;body onLoad="disableUse(document.forms[0].test)"&gt;
&lt;form&gt;
&lt;select name="test" id="test"&gt;
&lt;option valuue="dfd"&gt;adfds&lt;/option&gt;
&lt;option valuue="dfd"&gt;bfbf&lt;/option&gt;
&lt;option valuue="dfd"&gt;cccc&lt;/option&gt;
&lt;/select&gt;
&lt;/form&gt;
&lt;/body&gt;






Copy linkTweet thisAlerts:
@crh3675Sep 03.2004 — <i>
</i>
&lt;script type="text/javascript"&gt;

var disablers=0;

function posLeft(eElement)
{
var nLeftPos = eElement.offsetLeft; <br/>
var eParElement = eElement.offsetParent; <br/>
while (eParElement != null)
{ <br/>
nLeftPos += eParElement.offsetLeft; <br/>
eParElement = eParElement.offsetParent; <br/>
}
return nLeftPos; <br/>
}

function posTop(eElement)
{
var nTopPos = eElement.offsetTop; <br/>
var eParElement = eElement.offsetParent; <br/>
while (eParElement != null)
{ <br/>
nTopPos += eParElement.offsetTop; <br/>
eParElement = eParElement.offsetParent; <br/>
}
return nTopPos; <br/>
}


function disableUse(obj){

<i> </i>var oTop=posTop(obj);
<i> </i>var oLeft=posLeft(obj);
<i> </i>var oWidth=obj.offsetWidth-2;
<i> </i>var oHeight=obj.offsetHeight-8;

<i> </i>obj.style.visibility="hidden";

<i> </i>if(obj.type.match(/select/)){
<i> </i> value=obj.options[obj.selectedIndex].value;
<i> </i>}
<i> </i>if(obj.type.match(/text/)){
<i> </i> value=obj.value;
<i> </i>}

<i> </i>var myDiv=document.createElement("DIV");
<i> </i>myDiv.id="disabler"+(disablers++);
<i> </i>myDiv.style.position="absolute";
<i> </i>myDiv.style.left=oLeft+"px";
<i> </i>myDiv.style.top=oTop+"px";
<i> </i>myDiv.style.width=oWidth+"px";
<i> </i>myDiv.style.height=oHeight+"px";
<i> </i>myDiv.style.backgroundColor="transparent";
<i> </i>myDiv.style.zIndex=200;
<i> </i>myDiv.style.border="2px inset #C0C0C0";
<i> </i>myDiv.setAttribute("title","This field is not editable.");
<i> </i>myDiv.innerHTML=value;

<i> </i>document.body.appendChild(myDiv);
}

&lt;/script&gt;

&lt;body onLoad="disableUse(document.forms[0].test)"&gt;
&lt;form&gt;
&lt;select name="test" id="test"&gt;
&lt;option value="dfd" selected="selected"&gt;adfds&lt;/option&gt;
&lt;option value="dfd"&gt;bfbf&lt;/option&gt;
&lt;option value="dfd"&gt;cccc&lt;/option&gt;
&lt;/select&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;select name="test2" id="test2"&gt;
&lt;option value="dfd" selected="selected"&gt;adfds&lt;/option&gt;
&lt;option value="dfd"&gt;bfbf&lt;/option&gt;
&lt;option value="dfd"&gt;cccc&lt;/option&gt;
&lt;/select&gt;
&lt;/form&gt;
&lt;/body&gt;

Copy linkTweet thisAlerts:
@crh3675Sep 03.2004 — If you are not worried about valid code, them create a custom attribute and use:

<i>
</i>&lt;script type="text/javascript"&gt;

var disablers=0;

function posLeft(eElement)
{
var nLeftPos = eElement.offsetLeft; <br/>
var eParElement = eElement.offsetParent; <br/>
while (eParElement != null)
{ <br/>
nLeftPos += eParElement.offsetLeft; <br/>
eParElement = eParElement.offsetParent; <br/>
}
return nLeftPos; <br/>
}

function posTop(eElement)
{
var nTopPos = eElement.offsetTop; <br/>
var eParElement = eElement.offsetParent; <br/>
while (eParElement != null)
{ <br/>
nTopPos += eParElement.offsetTop; <br/>
eParElement = eParElement.offsetParent; <br/>
}
return nTopPos; <br/>
}


function disableUse(){

<i> </i>var all=document.getElementsByTagName("*");

<i> </i>for(i=0;i&lt;all.length;i++){

<i> </i> obj=all[i];

<i> </i> if(obj.getAttribute("disableUse")=="true"){

<i> </i> var oTop=posTop(obj);
<i> </i> var oLeft=posLeft(obj);
<i> </i> var oWidth=obj.offsetWidth-2;
<i> </i> var oHeight=obj.offsetHeight-8;

<i> </i> obj.style.visibility="hidden";

<i> </i> if(obj.type.match(/select/)){
<i> </i> value=obj.options[obj.selectedIndex].value;
<i> </i> }
<i> </i> if(obj.type.match(/text/)){
<i> </i> value=obj.value;
<i> </i> }

<i> </i> var myDiv=document.createElement("DIV");
<i> </i> myDiv.id="disabler"+(disablers++);
<i> </i> myDiv.style.position="absolute";
<i> </i> myDiv.style.left=oLeft+"px";
<i> </i> myDiv.style.top=oTop+"px";
<i> </i> myDiv.style.width=oWidth+"px";
<i> </i> myDiv.style.height=oHeight+"px";
<i> </i> myDiv.style.backgroundColor="transparent";
<i> </i> myDiv.style.zIndex=200;
<i> </i> myDiv.style.border="2px inset #C0C0C0";
<i> </i> myDiv.setAttribute("title","This field is not editable.");
<i> </i> myDiv.innerHTML=value;

<i> </i> document.body.appendChild(myDiv);
<i> </i> }
<i> </i>}
}

&lt;/script&gt;

&lt;body onload="disableUse()"&gt;
&lt;form&gt;
&lt;select name="test" id="test" disableUse="true"&gt;
&lt;option value="dfd" selected="selected"&gt;adfds&lt;/option&gt;
&lt;option value="dfd"&gt;bfbf&lt;/option&gt;
&lt;option value="dfd"&gt;cccc&lt;/option&gt;
&lt;/select&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;select name="test2" id="test2"&gt;
&lt;option value="dfd" selected="selected"&gt;adfds&lt;/option&gt;
&lt;option value="dfd"&gt;bfbf&lt;/option&gt;
&lt;option value="dfd"&gt;cccc&lt;/option&gt;
&lt;/select&gt;
&lt;/form&gt;
&lt;/body&gt;






Copy linkTweet thisAlerts:
@MaxHewittauthorSep 04.2004 — All cool stuff!

I'm designing the site for IE, since that is what all of our offices use, but glad to have the additional info!

Thanks All!
×

Success!

Help @MaxHewitt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...