Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

I am trying to set a value into a textbox which is in a div that is created with a Javascript function, can you please review my code and tell me why I am getting errors and incorrect values.
JavaScript
var searchaddress = document.getElementById('autocomplete').value;
document.getElementById('C_I_add').nodeValue = searchaddress;
var popup = $('<div><h1>Coverage Issue Log</h1><br>
<p> Name <input  type="text" onkeyup="" id="Name" style=" width: 300px; margin-left: 30px"/></p>
//This is the textbox I am trying to assign the value searchaddress
<br><p> Coverage Issue address <input  type="text" readonly="readonly" id="C_I_add" value = searchaddress style=" width: 300px; margin-left: 30px"/></p><br>
<p> Comments <textarea  type="text" id="Comments" rows="5" style=" width: 300px; margin-left: 30px"/></p><br>
<p> Cellphone Number <input  type="text" onkeyup="" id="CellNo" style=" width: 300px; margin-left: 30px"/></p></div>').dialog({
                'autoOpen': false,
                'width': 600,
                'height': 600,
                'resizable': false,
                'modal': true,
                'title': name,
                dialogClass: 'Dialog-Class'
            });
Posted
Updated 20-May-13 1:51am
v2
Comments
Naz_Firdouse 20-May-13 5:53am    
what error you are getting?
mlingo209 20-May-13 5:55am    
the word searchaddress appears as the value in the textbox and not the value in the variable
Sunasara Imdadhusen 20-May-13 7:53am    
Which variable are talking about?
mlingo209 20-May-13 7:56am    
this: var searchaddress = document.getElementById('autocomplete').value;
the text value of the text box autocomplete is suppose to be populated in searchaddress
then i want it to appear here
<input type="text" readonly="readonly" id="C_I_add" value = searchaddress style=" width: 300px; margin-left: 30px"/>

1 solution

<input type="text" readonly="readonly" id="C_I_add" value="searchaddress" style=" width: 300px; margin-left: 30px" />

In this line your searchaddress variable is inside the string as text, you should break the string and concatenate the variable to the string like this:
<input type="text" readonly="readonly" id="C_I_add" value="' + searchaddress +  '" style=" width: 300px; margin-left: 30px" />

Notice that I'm closing the string with ' and concatenate the variable with the +

And on other note, if I recall correctly Javascript is not too fond of breaking strings with line breaks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900