Page 1 of 1

if textbox value contains 'string' then set string readonly

Posted: Tue Nov 05, 2013 8:35 am
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

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

Posted: Tue Nov 05, 2013 2:20 pm
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.

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

Posted: Wed Nov 06, 2013 4:25 am
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'.

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

Posted: Wed Nov 06, 2013 5:38 am
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