Jump to content

Changing input element type


mrsquash

Recommended Posts

I have a radio button group on my form.  When one of the buttons is selected I am using an "onclick" event to call a function. I want this function to change the input type of a text field from hidden to text.  I keep getting an error message that parentNode is null or not an object.  Below is my code.  Any ideas?

 

My button set:

<input type="radio" tabindex="49" name="suspended" value="Y" onclick="javascript:showDate('suspend_date', 'hidden');"><span class="small">Yes</span> 
<input type="radio" name="suspended" value="N" /><span class="small">No</span>

 

My input element I want to update:

<input type="hidden" tabindex="50" value="" size="10" maxlength="25" name="suspend_date">

 

My javascript function to update the element:

function showDate(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = "text";
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}

Link to comment
Share on other sites

So something like this?

function showDate(id) {
  document.getElementById('id').type = 'text';
  var newObject = document.createElement('input');
  newObject.type = "text";
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}

Link to comment
Share on other sites

I was under the impression that to get it to work with Internet Explorer you had to create a new element and remove the old element.

 

Okay, I changed it to this:

 

My button set:

<input type="radio" tabindex="49" name="suspended" value="Y" onclick="javascript:showDate();"><span class="small">Yes</span> 
<input type="radio" name="suspended" value="N" /><span class="small">No</span>

 

My input element I want to update:

<input type="hidden" tabindex="50" value="" size="10" maxlength="25" name="suspend_date" id="1">

 

My javascript function to update the element:

function showDate() {
  document.getElementById('1').type = 'text';
}

 

And it gives me the following: Could not get the type property. This command is not supported.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.