1

I have a select with ROWID in the value and the name in the value,

<select name="opcoes"  onchange="showInfo(this.value)">
<option value=''>Select</option>
<option value=6>A</option>
<option value=2>F</option>
<option value=5>L</option>
<option value=1>M</option>
</select>

when you select one i have this ajax code to create a form with php,

    function showInfo(str)
{


if (str=="")
  {

  document.getElementById("fields").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("fields").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/vendors/getRow.php?id="+str,true);
xmlhttp.send();
}

Next if the selected value isnt "" it goes to the php,

...conection to the database...

echo "<form action='/php/vendors/edit.php' onSubmit=\"return confirm('Deseja editar?')\" method='post' >"; 
echo "<td><input type='text' name='editname'   value='".utf8_encode($linha[vendor_name])."'    ></td>";
echo "<td><input type='text' name='editemail'    value='".utf8_encode($linha[vendor_email])."'    ></td>";
echo "<td><input type='text' name='editwebsite'    value='".utf8_encode($linha[vendor_website])."'  ></td>";
echo "<td><input type='text' name='editphone'    value='".utf8_encode($linha[vendor_phone])."'    ></td>";
echo "<td><input type='text' name='editfax'     value='".utf8_encode($linha[vendor_fax])."'     ></td>";
echo "<td><input type='text' name='editadress'    value='".utf8_encode($linha[vendor_adress])."'   ></td>";
echo "<td><input type='text' name='editincharge'   value='".utf8_encode($linha[vendor_incharge])."'  ></td>";
echo "<td class='btn'><input class='edit' type='submit' value=''></td>";
echo "</form>";

It displays every information correctly the ONLY problem is that it does not submit when i click the input submit button... any ideas why?

9
  • Is the function defined before or after the HTML elements? If before, you should wrap it inside a window.onload and assign the onclick from there Commented Jul 16, 2013 at 9:16
  • i link the script in the head of the html... i didnt understand what you meant... it is called after the page loads and the user selects an option Commented Jul 16, 2013 at 9:18
  • is the confirm dialog shown? Commented Jul 16, 2013 at 9:20
  • no :( nothing dont know why :D Commented Jul 16, 2013 at 9:21
  • Any errors in the console (F12)? Commented Jul 16, 2013 at 9:21

2 Answers 2

2

You are generating invalid HTML.

A form can contain an entire table. A table cell can contain an entire row. A form cannot exist inside a table but around a set of cells in that table.

Your browser is error recovering by moving the form to after the table but leaving the form controls behind.

This means that the submit button isn't inside a form so it can't submit a form.

Sign up to request clarification or add additional context in comments.

6 Comments

@André Alvarez As Quentin said, you have error in building form, first correct your html then try again
But this bit of code is inserted inside a <table> with a div if you check the ajax code "fields" in the html there is a <tr id="fields">
@AndréAlvarez — That's my point. <tr><form><td></td></form></tr> is invalid and will not work.
So it should be? <form><tr><td></td></tr></form>
No! Read the answer! You have to put the form around the entire table or entirely inside a single cell.
|
0

If you load dynamically HTML forms in your document, they aren't registered in the DOM. Try to get this work with jQuery delegates jQuery Delegates

3 Comments

They are registered in the DOM, just not when the page is loaded … but since the event handlers are not bound at page load time, that doesn't matter.
i think quentin is right. But using jquery is allways a good idea because he is able to replace the ugly selfmade xmlhttprequest with jquerys $.ajax...
You can have neater XHR code without resorting to the overhead of jQuery.

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.