473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Firefox won't let me insert a new form..?

I'm trying to use AJAX to insert a form into a webpage (straight out of the Bulletproof AJAX book) but for some reason when I run it using Firefox the <form action=''...> code is deleted and not inserted. It works fine in Safari/IE.

Does anyone know what is going on here? Is there some XSS security thing going on?

I'm just using .innerHTML= to update the HTML with the form.
Oct 3 '07 #1
5 2508
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Can you post your code?
Oct 3 '07 #2
Thank you acoder.

The haddphoneaccount.cgi called by ajax returns a form. Below is the generated source that firefox has, first when the form is hardcoded into the page, secondly when the same form is inserted with .innerHTML

hardcoded
Expand|Select|Wrap|Line Numbers
  1. <div id="addphoneaccount"><input name="userid" value="xxx" type="hidden">
  2. <form name="addphoneaccountform" action="" id="addphoneaccountform" method="post">
  3. <h1>addphoneaccount for xxx</h1><table id="tableaddphoneaccount" class="tableaddphoneaccount"> <tbody>
  4. <tr><td>Account Name: </td><td><input name="phoneaccountname" value="" type="text"></td></tr>
  5. <tr><td><input type="submit"></td></tr></tbody></table></form></div></form></div></div></body></html>
ajax inserted
Expand|Select|Wrap|Line Numbers
  1. <div id="addphoneaccount"><h1>addphoneaccount for </h1><table id="tableaddphoneaccount" class="tableaddphoneaccount"> 
  2. <input name="userid" value="" type="hidden"><tbody>
  3. <tr><td>Account Name: </td><td><input name="phoneaccountname" value="" type="text"></td></tr>
  4. <tr><td><input type="submit"></td></tr></tbody></table></div></form></div></div></body></html>
You can see that for some reason Firefox cuts out the <form..> part of the htmt that is inserting.



Full JS code below.
Expand|Select|Wrap|Line Numbers
  1. function prepareForm()
  2. {
  3.     if(!document.getElementById)
  4.         {
  5.             return;
  6.         }
  7.     if(!document.getElementById("addphoneaccountform"))
  8.         {
  9.             return;
  10.         }
  11.     document.getElementById("addphoneaccountform").onsubmit = function()
  12.     {
  13.         var data ="";
  14.         for (var i=0; i<this.elements.length; i++)
  15.             {
  16.                 data+= this.elements[i].name;
  17.                 data+="=";
  18.                 data+= escape(this.elements[i].value);
  19.                 data+= "&";
  20.             }
  21.         alert(data);
  22.         return !sendData(data);
  23.     };
  24.  
  25. }
  26. function sendData(data)
  27. {
  28.     var request = getHTTPObject();
  29.     var url = 'haddphoneaccount.cgi';
  30.     if(request)
  31.         {
  32.             request.onreadystatechange = function()
  33.             {
  34.                 parseResponse(request);
  35.             };
  36.             request.open("POST", url, true);
  37.             request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  38.             request.send(data);
  39.             return true;
  40.         }
  41.     else
  42.         {
  43.             return false;
  44.         }
  45. }
  46.  
  47. function parseResponse(request)
  48. {
  49.     //    alert("paser"+request+" rs:"+request.readyState+" st"+request.status);
  50.     if (request.readyState == 4)
  51.         {
  52.             if (request.status == 200 || request.status == 304)
  53.                 {
  54.                     var addphoneaccount = document.getElementById('addphoneaccount');
  55.                     alert(request.responseText);
  56.                     addphoneaccount.innerHTML = request.responseText;
  57.                     prepareForm();
  58.                 }
  59.  
  60.         }
  61. }
  62. window.onload=prepareForm;
  63.  
Oct 3 '07 #3
Ok. I've found a page which says that you can't just put form code in a DIV, but you must add it to the dom. I'll try that I guess...
Oct 3 '07 #4
whatever the new form u created or replacing the older form just keep the form outside the table tag<form><table></table></form> it looks small thing for me it works after a long search by changing this works fine
Oct 23 '07 #5
Ferris
101 100+
there's no problem to insert a new form by using innerHTML,but the problem I guess,is that you add the form into another form.this is illegal.

for example,you cann't code like this:
<form id="form1">
<form id="form2">
</form>
</form>


and in your hardcoded, I can see that you really do this:

</form></div></form>

maybe it can work in Safari or IE,but not in firefox.firefox found you want to insert a form inside another form,it will remove the new one automatically,so you can't see <form action=.....> and </form>.

so,check your code.

hope it helps. :)
Oct 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: johnd126 | last post by:
I have a cgi program which outputs a fairly hefty amount of html/javascript for doing a complex slide show sorta thing in a variety of areas in the browser. I accomplish this by creating a series...
23
by: dangerd | last post by:
hi there, I used css for a page, it worked but only in IE not in firefox. What DOCTYPE whould I use for firefox. the external stylesheet contains the following: body { background-color:...
5
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
1
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.