0

I want to extract data from the list and put it in the form using jquery!

I succeeded to know how to import data from "Last Name" and "First Name" of the list into text fields "Last name" and "First name" of the form by

<input type="text" id="lastname"/>

var x="";
x = x + x.get_item('Last_x0020_Name');
$("#lastname").val(x.toString());

I still have problem on select field (Age) and textarea filed (description)

enter image description here

1
  • Do you know the id for the Age field? Is the select field (Age) pre-populated or just or just get the options from the list?
    – cubanGuy
    Commented Aug 14, 2014 at 16:34

1 Answer 1

0

Try this:

HTML

<label for="ageList">Age from List</label>
<input type="text" id="ageList" />
<br></br>
<label for="ageForm">Age from Form</label>
<input type="text" id="ageForm" />
<br></br>
<label for="myselect">Age Dropdown</label>
<select id="myselect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

JS

$('#ageList').on('keyup', function () {
var theText = $("#ageList").val().toString();
$('#myselect option[value]').each(function () {
    if ($(this).attr("value") === theText) {
        $(this).attr("selected", "selected");

    }
$('#ageForm').val(theText);
});

});

The HTML code is just for reference, I'm sure yours is totally different. I hope this helps.

2
  • Thanks. My question now is how to remove a subsrting from a string. For exemple, when i extract data from a textarea , it appears to me the text that i want and also the balise like this div my text div so i want to delete div and div
    – user32312
    Commented Aug 15, 2014 at 8:58
  • If I understand your question correctly, to remove a substring from a string, one option would be to use replace(). check this link
    – cubanGuy
    Commented Aug 15, 2014 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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