You are viewing limited content. For full access, please sign in.

Question

Question

How to only use portions of a variable?

asked on April 23, 2018

So I want to take a the first few characters of a variable in my form and populate the title with that, how would I go about doing taking just the A.01. for example? Is there some kind of syntax I should be using to accomplish this?

0 0

Replies

replied on April 23, 2018

You could add a Class tag to your title like this

UTHA TRANSIT AUTHORITY CORPORATE POLICY NO. <span class="someDropDownValue"></span>

And then add the code below to your JavaScript section so that it changes when you change the value of the drop-down menu.

You will also need to add the Class "someDropDown" to your drop-down menu

$(document).ready(function () {
  
  $(document).on('change', '.someDropDown select',  doFunction);
  
  function doFunction() { 
    
   var someDropDown = $('.someDropDown select').val();
    
    var part_someDropDown = someDropDown.substr(0, 5);
    
    //alert(part_someDropDown);
    $('.someDropDownValue').html(part_someDropDown);
    
  }
  
});

 

title.PNG
drop-down.PNG
title.PNG (12.46 KB)
drop-down.PNG (10.76 KB)
2 0
replied on April 23, 2018

The issue is that I am saving the form to a location based on what they choose from that drop down. So for example, the location I would be saving this form would be A.01. Corporate Policies and SOPs. I want to retain this functionality while populating the UTAH TRANIST AUTHORITY CORPORATE POLICY NO. with just A.01 from the drop down. From my understanding with your method using javascript, the value of that drop down would change.

0 0
replied on April 23, 2018

The value of the drop-down would stay untouched. What the JavaScript does is that it reads the first 5 characters from left to right of the value in your drop-down menu and it uses that to populate your title. 

In your case, when you picked A.01. Corporate Policies and SOPs, the title would change to

UTHA TRANSIT AUTHORITY CORPORATE POLICY NO. A.01.

1 0
replied on April 25, 2018 Show version history

I tried the method you suggested, but when I save the form I only see "UTAH TRANSIT AUTHORITY CORPORATE POLICY NO.<span class="someDropDownValue"></span>". I cannot get that value to change. It may have to do with my "title" being a custom HTML element. I'm not actually using the title field.

0 0
replied on April 25, 2018

Does it load with the choice that you want first or do you physically have to pick it from the drop-down menu?

0 0
replied on April 25, 2018

This is what I see when filling out the form. 

form.JPG
form.JPG (70.32 KB)
0 0
replied on April 25, 2018

Is the "UTAH TRANSIT..." part of the banner? Is it embedded in the image? Otherwise it shouldn't be displaying HTML

0 0
replied on April 25, 2018 Show version history

It is not embedded in the image. My mistake, I was adding the <span class="someDropDownValue"></span> into the Visual content area instead of the HTML content area. I added the <span class="someDropDownValue"></span> into the HTML content area, but it still will not display "A.01." for the title.

0 0
replied on April 25, 2018

Ok. If you are using a Custom HTML field, make sure that you are pasting that content thru the HTML tab and not the Visual tab

 

html.PNG
html.PNG (14.97 KB)
0 0
replied on April 25, 2018

I moved it to the HTML tab and it will not save to the repository with the Policy No. A.01.

0 0
replied on April 25, 2018

Does it contain the A.01. when you save it?

0 0
replied on April 25, 2018

No it does not.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.