FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to add dynamic textbox (row) and save to database using PHP
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
How to add dynamic textbox (row) and save to database using PHP [message #179665] Fri, 16 November 2012 21:02 Go to next message
miyotz is currently offline  miyotz
Messages: 2
Registered: November 2012
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Hi. I have here my Javascript code that adds dynamic textbox (row) my problem is how can I save this to database using PHP script? How you can help me guys.. Thanks!

<script type="text/JavaScript">
function addRow(r){
var root = r.parentNode;//the root
var allRows = root.getElementsByTagName('tr');//the rows' collection
var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row
for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.lengt h+1))
}
root.appendChild(cRow);
}
function shownames(){
var allInp=document.getElementsByTagName('input');
for(var i=0;i<allInp.length;i++){
alert(allInp[i].name)
}
}
</script>

My HTML code:

<form method= POST> <table width="1024" border="0" cellspacing="6" cellpadding="0"> <tr> <td width="195"><div class="user"><input type="text" name="textfield_a" id="user" tabindex="6"/></div></td> <td width="410"><div class="reported"><input type="text" name="textfield_b" id="reported" tabindex="7"/></div></td> <td width="399"><div class="reported"><input type="text" name="textfield_c" id="reported" tabindex="8"/></div></td> <td width="10"><input name="button" type="button" value="+" onclick="addRow(this.parentNode.parentNode)"></td> </tr> </table> </form>
Re: How to add dynamic textbox (row) and save to database using PHP [message #179666 is a reply to message #179665] Fri, 16 November 2012 22:12 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 11/16/2012 9:02 PM, miyotz wrote:
> Hi. I have here my Javascript code that adds dynamic textbox (row) my problem is how can I save this to database using PHP script? How you can help me guys.. Thanks!
>
> <script type="text/JavaScript">
> function addRow(r){
> var root = r.parentNode;//the root
> var allRows = root.getElementsByTagName('tr');//the rows' collection
> var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
> var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row
> for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
> cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.lengt h+1))
> }
> root.appendChild(cRow);
> }
> function shownames(){
> var allInp=document.getElementsByTagName('input');
> for(var i=0;i<allInp.length;i++){
> alert(allInp[i].name)
> }
> }
> </script>
>
> My HTML code:
>
> <form method= POST> <table width="1024" border="0" cellspacing="6" cellpadding="0"> <tr> <td width="195"><div class="user"><input type="text" name="textfield_a" id="user" tabindex="6"/></div></td> <td width="410"><div class="reported"><input type="text" name="textfield_b" id="reported" tabindex="7"/></div></td> <td width="399"><div class="reported"><input type="text" name="textfield_c" id="reported" tabindex="8"/></div></td> <td width="10"><input name="button" type="button" value="+" onclick="addRow(this.parentNode.parentNode)"></td> </tr> </table> </form>
>

Since you are posting the form, the information will be in the $_POST
superglobal. Take a look at the contents of that.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to add dynamic textbox (row) and save to database using PHP [message #179667 is a reply to message #179666] Sat, 17 November 2012 01:39 Go to previous messageGo to next message
miyotz is currently offline  miyotz
Messages: 2
Registered: November 2012
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Yes but how can I get the values inserted in each textbox in a row? You see when the user click the "+" button, three textboxes in a row will be added.
Re: How to add dynamic textbox (row) and save to database using PHP [message #179668 is a reply to message #179667] Sat, 17 November 2012 02:49 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On Fri, 16 Nov 2012 22:39:36 -0800, miyotz wrote:

> Yes but how can I get the values inserted in each textbox in a row? You
> see when the user click the "+" button, three textboxes in a row will be
> added.

The content of each correctly named form element will be in the relevant
member of the $_POST array. Get it from there.

Jerry already told you this.

Rgds

Denis McMahon
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: why can`t close mysql_connect?
Next Topic: Data sanitation for mysql queries.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Dec 18 11:47:05 EST 2017

Total time taken to generate the page: 0.00745 seconds