0

I want a user to be able to a) specify a name for an input field, and then click a button to create it, whereby the name they specified becomes the name of the field. I am using jQuery. Here is what I have so far:

HTML:

<input id="paramName" type="text" class="inputForm" name="addFieldName"  placeholder="Name of Parameter" />
<input id="addParameter" class="inputButton" type="button" name="addField" value="Add New Parameter" />

jQuery:

function addParams() {

    var specifiedParam = $('#paramName').value;

    $('<input />', {
        id: specifiedParam
        }).insertAfter('#formTop'); 

}

The inserting of the form works, but the input fields have no name. I just want to use the value of the specifiedParam variable (as defined by the user when typing in the text field) for the name of the input field.

Any help? Thanks

1 Answer 1

1

You are getting the value wrong, It's .val() not value:

var specifiedParam = $('#paramName').val();

    $('<input />', {
        id: specifiedParam
        }).insertAfter('#formTop');

LIVE DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.