Hi guys...im very happy to interact with you all...I have a problem with my code..i would like to call the javascript value into php.. can any one help me plz....

:- this is my function

var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "text";
element2.name="name"+rowCount;
element2.value="name"+rowCount;
cell3.appendChild(element2);
..............................................................

:- i called like this

$child=$_POST['element3.name'];
...............................................................

In the above code....i want call element2.name...this is used to assign a name to a textbox....So how can i cal this into php.....help me plz......

SunD_g,

I guess the function is executed more than once and you end up with an unknown number of added <input> elements named "nameN", "nameN+1", "nameN+2", "nameN+3", "nameN+4" etc., where N is a positive integer.

One strategy would be to write N to a hidden form field each time the function is called.

<input type="hidden" name="addedElements" value="0" />
...
cell3.appendChild(element2);
document.myForm.addedElements.value = rowCount;

In php, you can now do something like this:

$addedElements = (int)$_POST['addedElements'];
for($i=1; $i<=$addedElements; $i++){
    if(isset($_POST['name'.$i])){
        $child = $_POST['name'.$i];
        // do whatever you need to do with the user's entered value(s) here
    }
}

This should be error tollerant in that it will handle missing values up to $addedElements, eg, in case the series doesn't start at "name1".

(Nothing above is tested so will probably need debugging)

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.