Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

Help on VIew and JS

I have a view...that build a few controls...and has two buttons..with JS events..that need to pass the values from the view in the  javascript function calls..

Please help.


Here is the section of the view where the controls are defined mostly.  My insert call for example here need to pass the contactid..which will be on a hiddenfield passed into the page from another page when this page is rendered.
The other values the user will select.  One is a dropdownlist populated from my controller/model.
The other is a dropdown with static values.
ANd finally the last column is just a decimal value input on screen.
There is also a client value passed fro mthe user selection of an autocomplete dropdown...not seen in this view.  Those values all need to go in my insert ...which is just an ajax call back to a controller method from javascript.

 <table id="new-row-template" style="display:none">
        <tbody>
            <tr>
                <td>
                    <label></label> 
                </td> 
                <td>
                   @Html.DropDownList("DropDownListID", new SelectList(ViewBag.DDLRoles, "Value", "Text"), "--- Please Choose an Item! ---")
                </td>
                <td>
                    <select id="selectdesignate" name="selectdesignate" class="form-control">
                        <option value="1"></option>
                        <option value="2">Primary</option>
                        <option value="2">Secondary</option>
                    </select>
                </td>
                <td>                  
                    <input type="number"  placeholder="0.00" step="0.01"  id="txtAllocation">%
                </td>
                <td>
                    <button type="button" id="btnInsertContactEntity" class="btn btn-primary btn-xs actionButton" onclick="javascript:return insertContactClient(contactId,clientName);">Save</button>                  
                </td>
                <td>
                    <button type="button" id="btnDeleteContactEntity" class="btn btn-danger btn-xs actionButton"  onclick="javascript:return RemoveContactClient(contactId,clientName);">Remove</button>
                </td>
            </tr>
        </tbody>
    </table>   

Open in new window

Avatar of Robb Hill
Robb Hill
Flag of United States of America image

ASKER

I added  this...but do not seem to be getting the value ---

//Dropdownlist Selectedchange event
$('#ddlRole').change(function () {
// Get Dropdownlist seleted item text
$("#Text").text($("#ddlRole option:selected").text());
  var ddlText = $("#Text").text($("#ddlRole option:selected").text());
// Get Dropdownlist selected item value
$("#Value").text($("#ddlRole").val());
})
})

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Vish K
Vish K

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
not sure I understand
Also here is where I load up the dropdownlist in my controller.

I simply need to grab the selected value ...and pass it in the javascript function......that is associated to the save button


 IContactEntityEditService contactEntityEditService = DependencyResolver.Current.GetService<IContactEntityEditService>();
            List<string> roles = contactEntityEditService.GetContactLinkedEntitiesRoles();

            IEnumerable<SelectListItem> selectRoles = roles
                                         .Select(i => new SelectListItem()
                                         {
                                             Text = i.ToString(),
                                             Value = i
                                         });
            ViewBag.DDLRoles = selectRoles;

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have the 4 controls on the View as I pasted above.

I need to get the values of these controls when the user clicks select...which will call a javascript function..that will pass the values chosen..


If this way does not work..then what other way.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I dont think we are talking the same thing.


So I have this function  insertContactClient

<button type="button" id="btnInsertContactEntity" class="btn btn-primary btn-xs actionButton" onclick="javascript:return insertContactClient(contactId,clientName,);">Save</button>                

When I click this button ......on the client I want to pass something like this as one of the params

 $("#ddlRole :selected").text();


Can I do that?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
greetings  Robb Hill, , ,  I am still somewhat confused by what information you need to get from the select input, and how you need to transfer - pass to next operation, I can see some about your Click function, to start that process to get a text data, and AJAX it,
BUT
I seem to see that you want the <option> TEXT display and not the VALUE data,
Is this correct, if it is, then I would suggest that you change your server processes for ajax to use the VALUE and not the TEXT to get results.

But maybe I do not really get what you need at all? ?

can you say a small explain about what is in this select list (products, names colors) AND what the server is doing with the AJAX, to send back a response? ?