script on adds first word

G

groups2

In this example, if officename has more than one word, the only word
added to the input field is the first word.

document.getElementById('office').innerHTML="Office / Company
Name:<input type='text' name='org' size='30' id='org'
value="+officename+" />";

What happened to the other words and How do I get it to show all the
words ?
 
L

Lee

(e-mail address removed) said:
In this example, if officename has more than one word, the only word
added to the input field is the first word.

document.getElementById('office').innerHTML="Office / Company
Name:<input type='text' name='org' size='30' id='org'
value="+officename+" />";

What happened to the other words and How do I get it to show all the
words ?

Look at it the way the browser will see it.

If officename has the value "alpha beta", what will the innerHTML
be set to?

Office / Company Name:<input type='text' name='org' size='30' id='org'
value=alpha beta />";

Notice that there are no quotes around the text you're trying to
add as the value of the "value" attribute. In this case "beta"
is just some nonstandard attribute that you're naming, but not
assigning a value to.

document.getElementById('office').innerHTML="Office / Company
Name:<input type='text' name='org' size='30' id='org'
value='"+officename+"'>";


--
 
R

Randy Webb

(e-mail address removed) said the following on 6/10/2007 12:29 PM:
In this example, if officename has more than one word, the only word
added to the input field is the first word.

document.getElementById('office').innerHTML="Office / Company
Name:<input type='text' name='org' size='30' id='org'
value="+officename+" />";

What happened to the other words and How do I get it to show all the
words ?

Stop trying to use innerHTML to create form elements, use createElement
and appendChild and then set the input's .value property.
 
G

groups2

(e-mail address removed) said the following on 6/10/2007 12:29 PM:




Stop trying to use innerHTML to create form elements, use createElement
and appendChild and then set the input's .value property.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Ok, but that bought up a couple more questions.
Are you against innerHTML generally or just for this purpose ?

If I want to uncreate an input element, should I use innerHTML==''?
If I want to add text to a div can I use either innerHTML='text' or
createTextNode?
If I want to delete text from a div, what do I use ?
 
G

groups2

(e-mail address removed) said the following on 6/10/2007 12:29 PM:




Stop trying to use innerHTML to create form elements, use createElement
and appendChild and then set the input's .value property.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

I created an input element with createElement and appended it to a div
inside a form. It looks all right on the web page but when I submit
the form it does not post the value of that input. The only thing I
can think of is that input is not a part of the form. Am I supposed to
append it to the form somehow ?
 
R

Randy Webb

(e-mail address removed) said the following on 6/10/2007 4:19 PM:
Ok, but that bought up a couple more questions.
Are you against innerHTML generally or just for this purpose ?

No, just for this purpose. I am also against not trimming signatures.
If I want to uncreate an input element, should I use innerHTML==''?

removeChild is your friend.
If I want to add text to a div can I use either innerHTML='text' or
createTextNode?

Simple text, use either.
If I want to delete text from a div, what do I use ?

removeChild or set the innerHTML to ''
 
R

Randy Webb

(e-mail address removed) said the following on 6/10/2007 4:44 PM:
I created an input element with createElement and appended it to a div
inside a form. It looks all right on the web page but when I submit
the form it does not post the value of that input. The only thing I
can think of is that input is not a part of the form. Am I supposed to
append it to the form somehow ?

Yes, appendChild to the formElement, not a div element.
 
G

groups2

(e-mail address removed) said the following on 6/10/2007 4:44 PM:




Yes, appendChild to the formElement, not a div element.

I actually got it to work with either, the problem was I needed to set
the name attribute.
However if I append it to the form, it goes to the bottom of the form
and I don't want that. I want it in the middle of the form, in the div
that is there for that input. Is there a way to append it to the form
and have it display where I want it ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top