Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Setting the value of a control using javascript

$
0
0

I feel like this is a very simple question, but in searching other questions, it seems like this one might be assumed to be so simple that it doesn't need to be asked. I'll bravely admit to my lack of javascript skills and ask away...

I've modified NewForm.aspx for a list so I could hide some fields. One of the fields I need to hide needs to be a required field for this list. So, I'd like to set the default value for this copy of NewForm.aspx only. It seems like the code I've got for hiding the fields (thank you other posters!) could help me out. I just can't quite figure out how. The bold bit is the one in questions.

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("hideFields");

function findacontrol(FieldName) {
   var arr = document.getElementsByTagName("!");
   // get all comments
   for (var i=0;i < arr.length; i++ )
   {
      // now match the field name
      if (arr[i].innerHTML.indexOf(FieldName) > 0)
      {         return arr[i];      }
   }
}

function hideFields() {
   var control = findacontrol("Request Status");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("Address");
   control.value = "N/A";
}
</script>

Can someone show me the way?

Thanks,

Mitch


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>