0

OK I am very new to JS and people have been great helping me out but I am having an issue creating a form with multiple input elements. The second element is appearing but the first element is populating with the input.value from the second element and I get no value in the second

I've not used the DOM functions before so I may be messing up how I am calling them. Any help is greatly appreciated

newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");  


newWindow.document.title = "Info Window";


// create a form and set properties
var form = document.createElement('form');
form.action = 'http://google.com';
form.method = 'post';

// insert into the body of the new window
newWindow.document.body.appendChild(form);

// add text before the input
var cNumLab = document.createElement('cNumLab');
form.appendChild(document.createTextNode('Craft Number:'));

// add a text input
var input = document.createElement('input');
input.type = 'text';
input.name = 'input';
input.value = 'Enter Craft Number Here';
form.appendChild(input);

//add linebreak
var linebreak = document.createElement('br');
form.appendChild(linebreak);

// add text before the input
var sDescL = document.createElement('sDescL');
form.appendChild(document.createTextNode('Short Desc:'));

// add a text input
var sDesc = document.createElement('input');
input.type = 'text';
input.name = 'sDesc';
input.value = 'Enter Short Description Here:';
form.appendChild(sDesc);
0

1 Answer 1

2

In your second "input" the variable references the first field "input" and not the later "sDesc"

Should be

// add a text input
var sDesc = document.createElement('input');
sDesc.type = 'text';
sDesc.name = 'sDesc';
sDesc.value = 'Enter Short Description Here:';
form.appendChild(sDesc);
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.