Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Display name value from dropdown in a HTML object

Locked
rnott
Posts: 31
Joined: Fri Mar 14, 2014 6:14 pm

Display name value from dropdown in a HTML object

Unread post by rnott »

Is there a way to display the name value (that is currently selected) from dropdown in a HTML object?
I know you can use the field name in a hash tag on the HTML tab to get the id value, but I need the name value.

The user would like to view its value on a different tab.
Thanks!
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Display name value from dropdown in a HTML object

Unread post by admin »

rnott,

$('#sex').text() = 'Male';
$('#sex').val() = 'm';

Is text() what you want?

Steven
rnott
Posts: 31
Joined: Fri Mar 14, 2014 6:14 pm

Re: Display name value from dropdown in a HTML object

Unread post by rnott »

yes I would like the text value to be displayed in a nuBuilder HTML object.
thanks,
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Display name value from dropdown in a HTML object

Unread post by massiws »

rnott,
place you html object where you want and give it an id (ie: <div id="mytext"></div>);
In Javascript tab of your form insert some code like this:

Code: Select all

function nuLoadEdit() {
  $( "#mytext" ).val( $( "#your-dropdown-field-id option:selected" ).text() );
}
This will display the value of dropdown in your html object every time the form is loaded.

Then, to make sure that every time you change the dropdown value also the html object change accordingly, insert a new event in Event tab of your dropdown object:

Code: Select all

$( "#mytext" ).val( $( "#your-dropdown-field-id option:selected" ).text() );
Obviously, you have to change "mytext" and "your-dropdown-field-id" to your needs.

Have a look at this video tutorial about Events in nuBuilder.

Hope this helps,
Max
rnott
Posts: 31
Joined: Fri Mar 14, 2014 6:14 pm

Re: Display name value from dropdown in a HTML object

Unread post by rnott »

Thanks! Its working!

Here's what I did.
Hope this helps someone!..

On HTML tab for the HTML object create id --> <div id="htmlObjState"></div>

Then paste the following code in form properties --> Custom Code --> Javascript tab:
function nuLoadEdit() {
loadDlStateNo();
}

function loadDlStateNo(){
// Get the text value from the dropdown
dlstate=$( '#emp_dl_state_id option:selected' ).text();

// Get the Driver License # value from the text object
dlno=$( '#emp_dl_no' ).val();
//alert(dlno);

// Concatenates State & Driver License # & set the text value for the HTML object
$("#htmlObjState").text(dlstate + ' ' + dlno);

}

Then go to the dropdown object properties --> Events Tab
Event Name = onchange
Javascript = loadDLStateNo();

Thanks
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Display name value from dropdown in a HTML object

Unread post by massiws »

.
Locked