if textbox value contains 'string' then set string readonly

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
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

if textbox value contains 'string' then set string readonly

Post by sectionLeader123 »

I have the following drop down list:

Code: Select all

<td><label>Job Status: 
</label></td>
<td><select onkeydown="return noesc()" id="JobStatus1" name="jobStatus1" onchange="editStat(this)"> 
<option value="Please Select">Please Select</option>
<option value="Job Accepted <?php echo $datestamp;?>" >Job Accepted <?php echo $datestamp;?></option>
</select>&nbsp;<input type="button" style="width: 60px; height: 30px;" id="edit1" value="Edit" onclick="show('JobStatus');"/>
<input type="button" style="width: 60px; height: 30px;" id="hide1" value="Hide" onclick="hide('JobStatus');"/>
<input onkeydown="return noesc()" style="width: 255px;" type="text" name="jobStatus" id="JobStatus"></td>
</tr>
When the edit button is clicked the jobStatus textbox is shown.
When the Job Accepted option is selected it automatically gets passed to the jobStatus textbox to allow the user to edit the date and time if needed.
I am using the editStat() function to pass the value to the textbox here:

Code: Select all

function editStat(data)
{
	document.getElementById("JobStatus").value = data.value;
}
This works fine but although the user is able to edit the date and the time, they can also edit the actual status itself, in this case 'Job Accepted'. Which is not necessary, is there any way I can run a check to see if the value in the textbox contains 'Job Accepted' and then set 'Job Accepted' to read only so it cannot be edited.

Many thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: if textbox value contains 'string' then set string reado

Post by Christopher »

You should be able to check if (document.getElementById("JobStatus").value == "Job Accepted") if that value is being copied there by the onChange.
(#10850)
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

Re: if textbox value contains 'string' then set string reado

Post by sectionLeader123 »

Would that not work though because the value is not equal to 'Job Accepted' it would be equal to 'Job Accepted plus the date and the time'.
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

Re: if textbox value contains 'string' then set string reado

Post by sectionLeader123 »

Could I do it this way:

Code: Select all

function editStat(data)
{
	document.getElementById("JobStatus").value = data;
	if(data.indexOf("Job Accepted")>=0)
	{
		data.indexOf("Job Accepted")=readOnly;
	}
}
This is incorrect but the idea is there, Check if data contains Job Accepted and if it does set Job Accepted to readonly.

Many Thanks
Post Reply