1

I`ve tried using JavaScript to update the field name: Apply with a Hyperlink. However, for what ever reason the code is not working as expected, thanks to Rajesh Sitaraman for the Code.

Please find below the code for review -

   <script type="text/javascript" src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript">
var setColumnValue = function (column, linkVal) {  
  var columnObj = $("input[Title='" + column + "']");         
   columnObj.val(linkVal);  
 }   
 $(document).ready(function() {
  setColumnValue('Apply','http://example.com');
 });
 </script>

Kindly suggest where the code needs refinement. Also, as an alternate solution tried Calculated columns (value set to Numeric) and provided the required hyperlink information in the formula section. The hyperlink appears in Allviews.aspx, but not visible in displayform.aspx or Newform.aspx.

Based on inputs from other in the community, it seems the viable option is CSR, so trying with JavaScript and need assistance.

1

Here is how I got it to work, added a script editor to the page and add the following modified script:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script>
     var setColumnValue = function (column, linkVal) {
     var columnObj = $("input[Title='" + column + "']");

     //this is what I changed    
     columnObj.attr('value',linkVal);
}

$(document).ready(function() { 
    setColumnValue('Apply','http://example.com'); 
});
</script>

enter image description here

  • thanks for your response. Ive tried adding the script as part of a script editor on the displayform.aspx page and place it below the form. But the JavaScript seems not doing the job as the field value name: Apply, doesn't appears to show any hyperlink. Later tried changing the value to Salary, below is the code (field name : Salary) code` $(document).ready(function() { setColumnValue('Salary','example.com'); }); code Above code only shows the changes section, rest all taken as what you had added. Please help – Jason May 24 '16 at 6:49
  • you have to use the Developer Tools (F12) and get the exact title of the field. (for example, Title field 's title is 'Title Required Field')...so what I am trying to say is that the column title might be different from the display name. The only way to figure this out is by using the Developer Tool. Also check the console tab of the developer tool for errors; it could be something else is throwing an error! Check the updated screen shot. – Ahmed Mahmoud May 24 '16 at 10:25
  • thanks so your assistance so far. Update, I would find the value for Filed: ApplyNow field as per Developer tool as : <h3 class="ms-standardheader"><a name="SPBookmark_test"></a>ApplyNow</h3> So my code should show - $(document).ready(function() { setColumnValue('SPBookmark_test','example.com'); }); My understanding, no other change in your code apart from the above? If yes, I tried but still no success. So let me get back to basics, in order to understand if I`ve missed. – Jason May 25 '16 at 2:29
  • I`m using the javascript on my dispform.aspx file by adding to a script editor and placing it below the form part of dispform.aspx. (Hope that is the correct approach) Once I get a success, wherein the field name: ApplyNow once cursor placed on it shows the Hyperlink or allows you to click in order to route you to the link (example.com) then will perform the same action for Newform.aspx. Hope that is overall the correct approach? – Jason May 25 '16 at 2:36
  • 1
    yes, it should. The only thing I was thinking about is why did you create it as a column, if the link is always the same URL. You can just added a new td at the end of your display form using jQuery like this $('input[title="choose the column name you want this to show up before it"]').parent().parent().parent().before("<td nowrap='true' valign='top' width='113px' class='ms-formlabel'><span class='ms-h3 ms-standardheader' style='font-size:14px;'><nobr><a href='www.google.com'>Apply</a></nobr></span></td>"); – Ahmed Mahmoud May 26 '16 at 14:10
0

@ahmed, Solution by Ahmed worked in my case.

Code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script>
 //Code to add url to the Hyperlink field part of Columna name: LinkURL -
     var setColumnValue = function (column, linkVal) {
     var columnObj = $("input[Title='" + column + "']");

     //this is what I changed    
     columnObj.attr('value',linkVal);
}

$(document).ready(function() { 
    setColumnValue('Link','www.example.com); 
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.