[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2325
  • Last Modified:

Javascript change HTML button value not working in iE7

I have to change the value of a button i.e. the button text.

I have to be able to click on a button on a row in the table and then fill  in the form and then clcik again and its disabled like before.

Problem is now that you click the edit button and it changes to save - you cannot change it back though. Cannot use two buttons as this makes more JS code (much more).

This is the HTML for it:

<?
                  while($company_contacts_row = mysql_fetch_array($company_contacts_query))
                  {      
                        echo "<tr>";      
                        echo "<td>";      
                        echo "<input type='text' name='type".$company_contacts_row['contact_id']."' id='type".$company_contacts_row['contact_id']."' value='".$company_contacts_row['type']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";  
                        echo "</td>";
                        
                        echo "<td>";
                        echo "<input type='text' name='name".$company_contacts_row['contact_id']."' id='name".$company_contacts_row['contact_id']."' value='".$company_contacts_row['title']." ".$company_contacts_row['fname']." ".$company_contacts_row['lname']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";  
                        echo "</td>";
                        
                        echo "<td>";
                        echo "<input type='text' name='mobile".$company_contacts_row['contact_id']."' id='mobile".$company_contacts_row['contact_id']."' value='".$company_contacts_row['mobile']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";  
                        echo "</td>";
                                                
                        echo "<td>";
                        echo "<input type='text' name='main_contact".$company_contacts_row['contact_id']."' id='main_contact".$company_contacts_row['contact_id']."' value='".$company_contacts_row['main_contact']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";  
                        echo "</td>";
      
                        echo "<td>";
                        echo "<input type='text' name='email".$company_contacts_row['contact_id']."' id='email".$company_contacts_row['contact_id']."' value='".$company_contacts_row['email']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";                          
                        echo "</td>";
                        
                        echo "<td>";
                        echo "<input type='text' name='responsible_for".$company_contacts_row['contact_id']."' id='responsible_for".$company_contacts_row['contact_id']."' value='".$company_contacts_row['responsible_for']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";  
                        echo "</td>";

                        echo "<td>";
                        echo "<input type='text' name='".$company_contacts_row['contact_id']."' id='".$company_contacts_row['contact_id']."' value='".$company_contacts_row['main_telephone']."' disabled style='background-color:#97baef;width:60px;border:1px solid #97baef;' onchange='makeLocked(this.id)'>";                          
                        echo "</td>";
                        
                        echo "<td width='25px'>";
                        echo "<input type='button' value='Edit' id='edit_button".$company_contacts_row['contact_id']."' name='edit_button".$company_contacts_row['contact_id']."' onClick='makeEditable(".$company_contacts_row['contact_id'].");'>";
                        echo "</td>";
                        
                        echo "<td width='30px'>";
                        echo "<input type='button' value='Remove' onClick='remove_contact(".$company_contacts_row['contact_id'].",".$company_id.");'>";                        
                        echo "</td>";                              
                        echo "</tr>";
                  }      
            }                  
            ?>

Also the second problem is that the fields when disabled have the wrong text colour - black would be better, is there a hack or alternative method for this.

Would really appreciated some help with this one.
Thanks
function makeEditable(whichOne)
{	
	if(document.getElementById(whichOne).disabled == true)
	{
		document.getElementById('name' + whichOne).disabled = false;
		document.getElementById('name' + whichOne).style.backgroundColor = "#ffffff";
		document.getElementById('type' + whichOne).disabled = false;
		document.getElementById('type' + whichOne).style.backgroundColor = "#ffffff";
 
		var name = document.getElementById('name' + whichOne).value;
		var type = document.getElementById('type' + whichOne).value;
 
		document.getElementById('edit_button' + whichOne).value = "Save";
		
		get_ajax();
 
		xmlHttp = new XMLHttpRequest();
		xmlHttp.open("GET", "secured/save_contact_row.php?contact_id=" + whichOne + "&name=" + name  + "&type=" + type + "&mobile=" + mobile + "&responsible_for=" + responsible_for + "&main_contact=" + main_contact + "&email=" + email, false);
		xmlHttp.send(null);	
		xmlDoc = xmlHttp.responseText;
		
		if(xmlDoc == 'redirect_index_open_add')
		{
			//alert("test1");
			window.location = 'index.php?cmd=editContact&pg=3&company_id=' + company_id + '';
		}
	}
	else if(document.getElementById(whichOne).disabled == false)
	{
		document.getElementById('name' + whichOne).disabled = true;
		document.getElementById('name' + whichOne).style.backgroundColor = "#97baef";
		document.getElementById('type' + whichOne).disabled = true;
		document.getElementById('type' + whichOne).style.backgroundColor = "#97baef";
 
		document.getElementById('edit_button' + whichOne).childNodes[0].nodeValue = "Edit";
	}
}
 
function makeLocked(whichOne)
{
    document.getElementById('name' + whichOne).disabled = true;
    document.getElementById('name' + whichOne).style.backgroundColor = "#97baef";
	document.getElementById('type' + whichOne).disabled = true;
    document.getElementById('type' + whichOne).style.backgroundColor = "#97baef";
 
	document.getElementById('edit_button' + whichOne).childNodes[0].nodeValue = "Edit";
}

Open in new window

0
ravinesolutions
Asked:
ravinesolutions
  • 2
1 Solution
 
ravinesolutionsAuthor Commented:
By the way the JS code has been shortened and anow only applies for 2 of the input fields for the sake of the example.
0
 
ravinesolutionsAuthor Commented:
This question no longer needs answering - I am changing the method inwhich I construct this form.

0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now