i want to basically take some information for the product and let the user
enter the the material required to make this product
1.first page test.php
which takes product code and displays prodcut anme have used
ajax to avoid refreshing of page this works fine
2.now i have created one row with
checkbox|select box|text|text|text|text|
where in the select box values are fetched from table here also i have used ajax for getting the m_name automatically withput refreshi works fine (onchange event)
3.after that i have given a add rows button on which rows are added dynamically
with the same like static row i have added
now i wantto use the same function i have used for static select box for avoiding refreshing here how do i pass the onchange event here
and after pressing submit button the dynamic rows created disappears
can anybody help me wot is wrong with this
how do i pass dynamic elements values from the rows to the php along with the static row values
my code is as follows - test.js
-
------------
-
// JavaScript Document
-
var xmlHttp;
-
function showCode(str)
-
{
-
xmlHttp=GetXmlHttpObject(); //Calls on the GetXmlHttpObject function to create an XMLHTTP object
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request");
-
return;
-
}
-
var url="testget.php"; //Defines the url (filename) to send to the server
-
url=url+"?p_cde="+str; //Adds a parameter (q) to the url with the content of the dropdown box
-
url=url+"&sid="+Math.random(); //Adds a random number to prevent the server from using a cached file
-
xmlHttp.onreadystatechange=stateChanged ; //Call stateChanged when a change is triggered
-
xmlHttp.open("GET",url,true); //Opens the XMLHTTP object with the given url.
-
xmlHttp.send(null); //Sends an HTTP request to the server
-
alert(url);
-
}
-
function showmcode(str)
-
{
-
xmlHttp=GetXmlHttpObject(); //Calls on the GetXmlHttpObject function to create an XMLHTTP object
-
alert(str);
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request");
-
return;
-
}
-
var url="testget.php"; //Defines the url (filename) to send to the server
-
url=url+"?m_cde="+str; //Adds a parameter (q) to the url with the content of the dropdown box
-
url=url+"&sid="+Math.random(); //Adds a random number to prevent the server from using a cached file
-
xmlHttp.onreadystatechange=stateChanged1 ; //Call stateChanged when a change is triggered
-
xmlHttp.open("GET",url,true); //Opens the XMLHTTP object with the given url.
-
xmlHttp.send(null); //Sends an HTTP request to the server
-
alert(url);
-
}
-
function stateChanged()
-
{
-
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
-
{
-
-
var ar=xmlHttp.responseText.split("|");
-
-
document.getElementById("p_name").value=ar[0] ;
-
document.getElementById("p_pckunit").value=ar[1] ;
-
-
-
}
-
}
-
-
function stateChanged1()
-
{
-
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
-
{
-
var ar=xmlHttp.responseText.split("|");
-
document.getElementById("m_name").value=ar[0] ;
-
document.getElementById("um").value=ar[1] ;
-
}
-
}
-
function GetXmlHttpObject()
-
{
-
var xmlHttp=null;
-
try
-
{
-
// Firefox, Opera 8.0+, Safari
-
xmlHttp=new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
//Internet Explorer
-
try
-
{
-
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
-
-
-
-
//FUNCTION FOR DYNAMIC ROW
-
-
j=0;
-
function add_rows(obj){
-
-
//tabObj = document.createElement("table");
-
//tbodyObj = document.createElement("tbody");
-
-
tabCols = new init_table();
-
trObj = document.createElement("tr")
-
col_names = new Array("chk","m_cde","m_name","um","qty","overages");
-
for(i=0;i<tabCols.length;i++){
-
tdObj = document.createElement("td");
-
/*
-
if(create_object(tabCols[i])=="select")
-
{
-
mselect=create_object(tabCols[i],col_names[i]+'['+j+']')
-
mselect.onChange=showmcode(col_names[i]+'['+j+']');
-
tdObj.appendChild(mselect));
-
}*/
-
-
tdObj.appendChild(create_object(tabCols[i],col_names[i]+'['+j+']'));
-
-
//added on 04/09/2007 for onchage event on select box
-
/* if(tabCols[i]=="select"){
-
alert("hi");
-
col_names[i]+'['+j+']'="fieldevent('"+fieldname+"')";
-
var showmcode=new Function(col_names[i]+'['+j+']'.onchange);
-
if(col_names[i]+'['+j+']'.addEventListener){
-
col_names[i]+'['+j+']'.addEventListener('change',showmcode,false);
-
else if(col_names[i]+'['+j+']'.attachEvent){
-
col_names[i]+'['+j+']'.attachEvent('onchange',showmcode);}
-
}
-
/* this is a sample
-
sfield.onchange = "fieldevent('" + fieldname + "')";
-
var onChangeHandler = new Function(sfield.onchange);
-
if (sfield.addEventListener) {
-
sfield.addEventListener('change', onChangeHandler, false );
-
} else if (sfield.attachEvent) {
-
sfield.attachEvent('onchange', onChangeHandler);
-
}
-
*/
-
trObj.appendChild(tdObj);
-
-
}
-
obj.firstChild.appendChild(trObj);
-
-
-
j++;
-
-
}
-
-
function fieldevent(fname){
-
-
alert (fname);
-
}
-
-
-
-
function init_table(){
-
tableProp = new Array();
-
-
tableProp[0] = "checkbox";
-
tableProp[1] = "select"; //m_cde
-
tableProp[2] = "text"; //m_name
-
tableProp[3] = "text"; //um
-
tableProp[4] = "text"; //qty
-
tableProp[5] = "text"; //overages
-
//tableProp[6] = "checkbox";
-
-
return tableProp;
-
}
-
-
function create_object(objType,nm){
-
if(objType == 'select'){
-
return getSelectBoxDOM(select_opt,nm);
-
}
-
-
obj = document.createElement("input");
-
obj.setAttribute("type",objType);
-
obj.setAttribute("name",nm);
-
-
-
return obj;
-
}
-
-
function getSelectBoxDOM(options,nm) {
-
selectBox =document.createElement('select');
-
for (x=0; x < options.length; x++) {
-
optionItem =document.createElement('option');
-
optionItem.appendChild(document.createTextNode(options[x]));
-
selectBox.appendChild(optionItem);
-
-
-
}
-
selectBox.setAttribute("name",nm);
-
-
-
return selectBox;
-
-
}
- testget.php
-
----------------
-
-
-
<?php
-
if($_GET)
-
{
-
-
$p_cde=$_GET['p_cde'];
-
-
-
$con = mysql_connect('localhost', 'localhost', ''); //PHP opens a connection to a MySQL server
-
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
mysql_select_db("erpmfg", $con);
-
$sql="select * from fgmaster where p_cde = '".$p_cde."'";
-
$result = mysql_query($sql);
-
while($row = mysql_fetch_array($result)){
-
$p_name=$row['p_name'];
-
$p_pckunit=$row['p_pckunit'];
-
echo $p_name."|".$p_pckunit;
-
}
-
}
-
-
if ($_GET)
-
{
-
-
$m_cde=$_GET['m_cde'];
-
-
$sqlmr="select * from materialmaster where m_cde = '".$m_cde."'";
-
$result1 = mysql_query($sqlmr);
-
-
while($row = mysql_fetch_array($result1)){
-
$m_name=$row['m_name'];
-
$um=$row['um'];
-
-
echo $m_name."|".$um;
-
}
-
}
-
-
-
mysql_close($con);
-
?>
21 29645
Please use Code tags then it will be easy to Solve your Problem.
Kind regards,
Dmjpro.
Leena, welcome to TSDN!
Did you know that you can specify languages in the code tags, e.g. [code=javascript]...[/code.] (remove the dot).
Give your dynamically created elements ids. For your select, add the onchange when you create the element.
- j=1;
-
function add_rows(obj){
-
-
tabCols = new init_table();
-
trObj = document.createElement("tr")
-
col_names = new Array("chk","m_cde","m_name","um","qty","overages");
-
for(i=0;i<tabCols.length;i++){
-
tdObj = document.createElement("td");
-
/* if(create_object(tabCols[i])=="select")
-
{
-
mselect=create_object(tabCols[i],col_names[i]+'['+j+']')
-
mselect.onChange=showmcode(col_names[i]+'['+j+']');
-
tdObj.appendChild(mselect));
-
}*/
-
-
tdObj.appendChild(create_object(tabCols[i],col_names[i]+'['+j+']'));
i was trying the above commented line in add_rows function while creating a select box using createElement function for onchange where am i going wrong
i was trying the above commented line in add_rows function while creating a select box using createElement function for onchange where am i going wrong
Use onchange (lower case "c").
i tried that but then my add rows button does not create new row some error
but if comment that part then it works
how to give onchage event when the select box is created - function getSelectBoxDOM(options,nm) {
-
selectBox =document.createElement('select');
-
for (x=0; x < options.length; x++) {
-
optionItem =document.createElement('option');
-
optionItem.appendChild(document.createTextNode(options[x]));
-
selectBox.appendChild(optionItem);
-
-
-
}
-
selectBox.setAttribute("name",nm);
-
selectBox.setAttribute("id",nm);
-
//after this say selectBox.onchange=showmcode(nm.value)........ ??????
-
where nm is the name of the selectbox
-
return selectBox;
-
}
-
i tried this bt giving error property not supported
thanks.
Please use code tags when posting code. Thanks!
You need to assign a function object to the onchange, not the result of the function. See this article.
Try: - selectBox.onchange = function() {
-
showmcode(selectBox.value);
-
}
i tried that but then my add rows button does not create new row some error
but if comment that part then it works
how to give onchage event when the select box is created - function getSelectBoxDOM(options,nm) {
-
selectBox =document.createElement('select');
-
for (x=0; x < options.length; x++) {
-
optionItem =document.createElement('option');
-
optionItem.appendChild(document.createTextNode(options[x]));
-
selectBox.appendChild(optionItem);
-
-
-
}
-
selectBox.setAttribute("name",nm);
-
selectBox.setAttribute("id",nm);
-
//after this say selectBox.onchange=showmcode(nm.value)........ ??????
-
where nm is the name of the selectbox
-
return selectBox;
-
}
-
-
i tried this bt giving error property not supported
thanks.
Make sure you use code tags. This is the final friendly request. The last post seems like a repeat of your previous comment.
- selectBox.onchange = function() {
-
showmcode(selectBox.value);
-
}
i did this but now it add a record but once i select value from dynamically added select box the value of m_name is not shown in corresponding text box there and my static rows um and m_name disappears which i had selected and where onchange event it had executed ajax script to display m_name and um
thanks
Try - selectBox.onchange = function() {
-
showmcode(this.value);
-
}
Don't forget to set the values of the option elements.
same problem i changes it to this.value
i'm setting the options in the getselectbox function
and then actual database values are passed in test.php program
can't understand what is wrong with my code
thanks
Try.. -
selectBox.onchange = function() {
-
showmcode(this.options[this.selectedIndex].value);
-
}
-
same problem i changes it to this.value
i'm setting the options in the getselectbox function
and then actual database values are passed in test.php program
can't understand what is wrong with my code
You're not setting the value of the options. Set the value by using .value or setAttribute, e.g. - optionItem.value = 'someval';
i writing a code to create select box - function getSelectBoxDOM(options,nm) {
-
selectBox =document.createElement('select');
-
for (x=0; x < options.length; x++) {
-
optionItem =document.createElement('option');
-
optionItem.appendChild(document.createTextNode(options[x]));
-
selectBox.appendChild(optionItem);
-
}
-
selectBox.setAttribute("name",nm);
-
selectBox.setAttribute("id",nm);
-
s=new function(){}
-
selectBox.onchange =new function() {
-
showmcode(this.options[this.selectedIndex].value);
-
}
-
return selectBox;
-
}
which is called here - function create_object(objType,nm){
-
if(objType == 'select'){
-
return getSelectBoxDOM(select_opt,nm);
-
//select_opt.onchange = function() {
-
// showmcode(this.options[this.selectedIndex].value);
-
// }
-
}
-
-
obj = document.createElement("input");
-
obj.setAttribute("type",objType);
-
obj.setAttribute("name",nm);
-
obj.setAttribute("id",nm);
-
-
return obj;
-
}
and when i'm adding rows the function create_object is called - function add_rows(obj){
-
-
//tabObj = document.createElement("table");
-
//tbodyObj = document.createElement("tbody");
-
-
tabCols = new init_table();
-
trObj = document.createElement("tr")
-
col_names = new Array("chk","m_cde","m_name","um","qty","overages");
-
for(i=0;i<tabCols.length;i++){
-
tdObj = document.createElement("td");
-
tdObj.appendChild(create_object(tabCols[i],col_names[i]+'['+j+']'));\
-
tdObj.appendChild(op.value);
-
trObj.appendChild(tdObj);
-
}
-
obj.firstChild.appendChild(trObj);
-
j++;
-
}
and in test.php i'm assigning values to options
so when the form is loaded select options are filled with database values
[PHP]<?
$sqlmaterial="select * from materialmaster order by m_cde";
$db_query_material=$DB_site->query($sqlmaterial);
while($rsmaterial=$DB_site->fetch_array($db_query_material)){
$option_vals[]=$rsmaterial['m_cde']."-".$rsmaterial['m_name'];
}
?>
<script>
select_opt = new Array();
<?
for($i=0;$i<count($option_vals);$i++){
?>
select_opt[<?= $i ?>] = '<?= $option_vals[$i] ?>';
<?
}
?>[/PHP]
now how and where to writea code to give onchange event to the select box
i tried create_object function where objtype="select" and where getselectbox function is called but same error.
i also tried in addrow function just after creating object ..
i'm new to ajax and dom
so please tell me how do do this
i have a static row where the same m_cde select box is there where this function is working prooerly
but when i do it for dynamic rows if i alert then it shows [object]
and with static rows it shows the allthe object created with id and all
also how do i pass the m_cde as arry to the url inthe showmcode function for rows .
thanks
but i'm assigning values to select box in the main program test.php from the database to the javascript array variable
and creating the select boxes in the test.js
so is it because of that it is creating problem?
Change line 5 in getSelectBoxDOM to: - optionItem.text = options[x];
-
optionItem.value = options[x];
You could use setAttribute if you want instead, e.g. - optionItem.setAttribute("value",options[x]);
Thanks
my onchange event function works in select option
but then it gives me error in mozilla
Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)"
this is in the add_rows function
when i try to append -
tdObj.appendChild(create_object(tabCols[i],col_names[i]+'['+j+']'));
-
trObj.appendChild(tdObj); }
-
obj.firstChild.appendChild(trObj); //this line the above error occurs
-
am i not setting the attributes in order the way it should for the objects created
and no rows are added dynamically
but in IE 6 it works and even the new rows are inserted
but the value of m_name is not assigned to the corresponding text box in then newly created row like it is shown in static row
how do i pass it in the test1.js in the statechaged1 corresponding to that row cell created
gits 5,390
Expert Mod 4TB
hi ...
please have a look at the correct usage of the code-tags:
[CODE=javascript] code goes here [/code]
kind regards
[quote=Leena P]i want to basically take some information for the product and let the user
enter the the material required to make this product
Thanks
my onchange event function works in select option
but then it gives me error in mozilla
Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)"
this is in the add_rows function
when i try to append -
tdObj.appendChild(create_object(tabCols[i],col_names[i]+'['+j+']'));
-
trObj.appendChild(tdObj); }
-
obj.firstChild.appendChild(trObj); //this line the above error occurs
-
You're trying to append to a whitespace node. Don't use firstChild. Use a tbody and append to that instead.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bart van Deenen |
last post by:
Hi all
I have a script where I dynamically create multiple inputs and selects
from a script. The inputs and selects must have an associated onchange
handler.
I have the script working fine on...
|
by: Stone Chen |
last post by:
Hello,
I have form that uses javascript createElement to add additional input
fields to it. However, my validating script will not process new input
fields because it can only find the named...
|
by: somaskarthic |
last post by:
Hi
In my php code , i dynamically created table rows on button click event.
Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the...
|
by: AndiSmith |
last post by:
Hi guys,
I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based...
|
by: nuchphasu |
last post by:
Hi
I have a problem on Dropdownlist that connect database
and retrieve data by Ajax.I write javascript like this
-------------------------------------------------------------------------...
|
by: coby |
last post by:
I have an application with a form that has two parts : A & B.
A should be a static form while B shoudl be dynamically loaded via AJAX/PHP.
Using a select box on part A, the onchange event calls...
|
by: bambr |
last post by:
I'm using following code:
function cloneRow(tBodyId, sourceRowId)
{
var obj = document.getElementById(tBodyId);
if(obj.tagName != 'TBODY')
{
for(var i = 0; i < obj.childNodes.length;...
|
by: shivendravikramsingh |
last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
|
by: sheldonlg |
last post by:
I am still improving my AJAX and I ran into something that I'm not sure
how to do.
I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. The...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |