473,624 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InnerHTML drops leading tag in SELECT

I am relatively new to XMLRequest, DOM and Ajax but I really like the
functionality. I have the DIV and SPAN changes working well but I
thought that I would experiment with changing the actual innerHTML of
each control rather than changing the whole control inside of a DIV.

What I tried was this:
Create a <SELECTso...

<SELECT id=MyComboBox>
<OPTION>opt1</OPTION>
<OPTION>opt2</OPTION>
<OPTION>opt3</OPTION>
</SELECT>

I then tried to change the innerHTML of just "MyComboBox " but when I
view the resulting string that is supposed to populate the SELECT it
is always missing the first <OPTIONtag. In other words, the string
is supposed to look like this:
strFill = "<OPTION>ne w1</OPTION><OPTION> new2</OPTION><OPTION> new3</
OPTION>"

....but, instead, it looks like this:
strFill = "new1</OPTION><OPTION> new2</OPTION><OPTION> new3</OPTION>"

I even tried forcing a leading string on the beginning like this...
strResult = "<OPTION>" + strFill;
but it still strips off the leading OPTION tag when I pop the SELECT
(ie. MyComboBox.inne rHTML = strResult;)
I checked the innerText property of the result and it looks fine.

Is there something that I am missing or is there an easier way to do
this?
Anyway, until I hear from someone, I guess that it is back to the DIV/
SPAN thing.

Thanks for the help.
Mark

Mar 30 '07 #1
10 2247
mj********@yaho o.com wrote:
I am relatively new to XMLRequest, DOM and Ajax but I really like the
functionality. I have the DIV and SPAN changes working well but I
thought that I would experiment with changing the actual innerHTML of
each control rather than changing the whole control inside of a DIV.

What I tried was this:
Create a <SELECTso...

<SELECT id=MyComboBox>
<OPTION>opt1</OPTION>
<OPTION>opt2</OPTION>
<OPTION>opt3</OPTION>
</SELECT>

I then tried to change the innerHTML of just "MyComboBox " but when I
view the resulting string that is supposed to populate the SELECT it
is always missing the first <OPTIONtag. In other words, the string
is supposed to look like this:
strFill = "<OPTION>ne w1</OPTION><OPTION> new2</OPTION><OPTION> new3</
OPTION>"

...but, instead, it looks like this:
strFill = "new1</OPTION><OPTION> new2</OPTION><OPTION> new3</OPTION>"

I even tried forcing a leading string on the beginning like this...
strResult = "<OPTION>" + strFill;
but it still strips off the leading OPTION tag when I pop the SELECT
(ie. MyComboBox.inne rHTML = strResult;)
I checked the innerText property of the result and it looks fine.

Is there something that I am missing or is there an easier way to do
this?
Anyway, until I hear from someone, I guess that it is back to the DIV/
SPAN thing.

Thanks for the help.
Mark
The select element has an options collection that contains all the
options. Use that to manipulate the options instead.

--
Göran Andersson
_____
http://www.guffa.com
Mar 30 '07 #2
The select element has an options collection that contains all the
options. Use that to manipulate the options instead.
Thanks for the quick reply!
I am trying to keep my javascript to a minimum in order to keep my
pages lightweight. I am mostly using the Jscript for events and Ajax.
I am using ASP.Net (C# scripting) objects on the backend to grab my
data and then populate the controls using the TextWriter classes to
send the HTML back to my pages.
ex:
StringWriter wr = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter( wr);
I have not tried your method (but I have thought about it) but my fear
is that the same thing will happen because I will populate the C#
object (my SELECT control) and then send the just the HTML back to the
page. So, there is really no difference. I will try it but I do not
think that it will make a difference.
Any other thoughts?

Thanks again,
Mark
Mar 30 '07 #3
<mj********@yah oo.comwrote in message
news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
>The select element has an options collection that contains all the
options. Use that to manipulate the options instead.
Thanks for the quick reply!
I am trying to keep my javascript to a minimum in order to keep my
pages lightweight. I am mostly using the Jscript for events and Ajax.
I am using ASP.Net (C# scripting) objects on the backend to grab my
data and then populate the controls using the TextWriter classes to
send the HTML back to my pages.
ex:
StringWriter wr = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter( wr);
Wow! I think you're really making life difficult for yourself!

There's almost never any need to actually write out the HTML markup,
especially for webcontrols...

If the data required to populate your DropDownList is being fetched from a
database, you can simply bind it:

MyDDL.DataSourc e = <fetch dataset from database>;
MyDDL.DataValue Field = "<column from dataset>";
MyDDL.DataTextF ield = "<column from dataset>";
MyDDL.DataBind( );

If not, you can add the select options like this:

MyDDL.Items.Add (new ListItem("OPTIO N1", "1"));
MyDDL.Items.Add (new ListItem("OPTIO N2", "2"));
MyDDL.Items.Add (new ListItem("OPTIO N3", "3"));
Mar 30 '07 #4
Wow! I think you're really making life difficult for yourself!
>
There's almost never any need to actually write out the HTML markup,
especially for webcontrols...

If the data required to populate your DropDownList is being fetched from a
database, you can simply bind it:

MyDDL.DataSourc e = <fetch dataset from database>;
MyDDL.DataValue Field = "<column from dataset>";
MyDDL.DataTextF ield = "<column from dataset>";
MyDDL.DataBind( );

If not, you can add the select options like this:

MyDDL.Items.Add (new ListItem("OPTIO N1", "1"));
MyDDL.Items.Add (new ListItem("OPTIO N2", "2"));
MyDDL.Items.Add (new ListItem("OPTIO N3", "3"));
Yes. That is exactly what I am doing. Sorry, I was try to be brief in
my prior description. But, I only want to update the values (aka
<OPTIONtags) *within* the control, not the entire DIV. Therefore, I
only want to update the internal markup (hence innerHTML) for the
control. I am using the method you are describing above but that
resulting .aspx (or asmx, whichever the case) will update the entire
control within the DIV on my webpage which forces me to resend my
jscript events for the control (ie. onclick=Validat eText();) everytime
I update the control.

Maybe I am missing something. Again, I am relatively new to this.

Thanks for the patience.

Mark

Mar 30 '07 #5
<mj********@yah oo.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
Yes. That is exactly what I am doing. Sorry, I was try to be brief in
my prior description. But, I only want to update the values (aka
<OPTIONtags) *within* the control, not the entire DIV. Therefore, I
only want to update the internal markup (hence innerHTML) for the
control. I am using the method you are describing above but that
resulting .aspx (or asmx, whichever the case) will update the entire
control within the DIV on my webpage which forces me to resend my
jscript events for the control (ie. onclick=Validat eText();) everytime
I update the control.

Maybe I am missing something. Again, I am relatively new to this.
Hmm - do you mean you want to update only a part of the page in isolation
without having to post the entire page back to the server...?

In which case, you need AJAX, as that is precisely the reason for which it
was developed...

Incidentally, since you say you're new to ASP.NET, you might find AJAX a bit
daunting...

In which case, you might prefer to use a relatively lightweight AJAX
wrapper: http://anthemdotnet.com/
Mar 30 '07 #6
That's pretty funny.
Did you read my first post?

Mark

Mar 30 '07 #7
<mj********@yah oo.comwrote in message
news:11******** *************@n 76g2000hsh.goog legroups.com...
Did you read my first post?
Not well enough, it seems...

No doubt you've solved your problem now anyway...
Mar 30 '07 #8
Hi,

Incase you are trying to alter the content of your select control in
javascript, you could try this option. Its not the innerHTML that needs to be
set, but its the other html.
<select id="myCombo" >
<option>opt1</option>
<option>opt2</option>
<option>opt3</option>
</select>

To replace the options inside the myCombo select control:

document.getEle mentById('myCom bo').outerHTML = "<select id='myCombo'>

<option>opt4</option>

<option>opt5</option>

<option>opt6</option>

</select>";
I think this shd help.

-Parvathy Padmanabhan

Mar 30 '07 #9
Unfortunately, I did not solve my problem but I am not sure that it is
possible.

Thanks for trying though.

Mar 30 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
10120
by: Christopher Benson-Manica | last post by:
I'm trying to dynamically change the contents of a select box by doing the following... function myfunc() { var obj=document.getElementById("objname"); // name of the select box var str=''; str+='<option>blah</option>'; obj.innerHTML=str; alert(obj.innerHTML); }
3
2571
by: mtz | last post by:
Hi there, It looks like safari has a problem with innerHTML. I have to change a dropdown depending on a selection in another dropdown. When I change the selection in the first dropdown the second apears, then when I change the selection in the second I can display it. If I try to repeat this again it's not working anymore. This works fine on several browsers under Windows. Here is the code: <select name="listOrder"...
4
8629
by: Michael Schuerig | last post by:
I'm trying to change the options of a select element by setting its innerHTML. Here's a demo case: <html> <head> <script language="javascript" type="text/javascript"> function addOpts() { var s = document.getElementById("s"); s.innerHTML = '<option>Opt1</option><option>Opt2</option>'; }
3
5288
by: soup_or_power | last post by:
Hi Sorry about the heading. I have a table with td consisting of lists with <select></select>. When I do a document.getElementById("element").innerHTML I don't see the selected item. IOW, the innerHTML is not dynamic. Is there some way to get the most recent selected without traversing through the list's options. Thank you
8
8422
by: McKirahan | last post by:
Firefox does not reflect selected option via innerHTML How do I get Firefox to reflect selected option values? <html> <head> <title>FFinner.htm</title> <script type="text/javascript"> function clicks() { document.getElementById("t1").value =
7
1750
by: MaryA | last post by:
Let me preface this with the fact that I am a newbie to HTML, XML and Javascript. Having said that, let me explain my dilemma: I am having a difficult time getting innerHTML to consistently return the entire HTML string when a <p> is part of the text. It somehow throws everything off. I am trying to store exam questions in an Oracle Database as XML. The XML I started with looked like this: <aicpcu id="XMLTEXT"><stem id="STEM">This...
6
7546
by: fmdevelopertim | last post by:
New to AJAX so sorry if this is simple. Have a page that gives the user a list to select a brand. Based on the brand selected it shows a list of sizes available using the following code: function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { document.getElementById("serverResponse").innerHTML =
0
4106
by: hagar | last post by:
Hi all, I have a problem which I can not understand why this is happening! Debugging this I actually see that it grabs first record then when stepping through code to the line rsImportTo.AddNew it drops first record and grabs second record and continues on no problems (but no 1st record in data set) I am reading a text file record 1 is a top of text file. see code below Private Sub CmdFetchNewData_Click() on Error Goto CmdfetchErr Dim...
5
2555
by: pjdeklerk | last post by:
I have a web page which has javascript which uses the innerHTML property of a <TD> object to replace that table cell's contents. The contents are of the form <span><select><option1.../><option2..>...</select></span> (in engish, the <td> contains a <span> which contains a <select> which contains some number of <option>s. It works fine in IE. In Firefox it displays fine but when I submit the form the name and value for the select tag are...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1493
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.