Jump to content
Sigmahokies

JavaScript and PHP same time

Recommended Posts

Hi everyone,

I want to make clear again. I am trying to get data from "name" by PHP in HTML, but problem is "name" is used up by Javascript, but I need "name" for PHP's $_POST to get data from input from html, but can I use this "name" by JavaScript and PHP in same time? I need to get data from that word to post in database, but I think I'm stuck now...Anyone can tell me what is alternative keyword to get data from "name" in HTML?

If you don't understand what I said, I will display and show you

Thanks,

Gary

Share this post


Link to post
Share on other sites

You probably need to show some code.  If you're talking about attributes, you use the name attribute to tell the browser how to submit a form.  That doesn't have anything to do with Javascript.

Share this post


Link to post
Share on other sites

Hi Justsomeguy,

Ok here my code, I replaced array ([ ]) to nothing in PHP, so PHP should able to get data from this name.

	<tr><td>Go/Walk-To/From</td>
        <td><label for="box"><input class="single-count" type="checkbox" id="box" name="chkboxGrp0[]" value="1"></label></td>
        <td class="vert-middle">0</td></tr>
    <tr><td>Bring-Stack-Comic</td>
        <td><input class="single-count" type="checkbox" name="chkboxGrp1[]" value="1"></td>
        <td class="vert-middle">0</td></tr>
    <tr><td>Pick-up</td></tr>
	

In JavaScript:

	 var inputNameArray = [];
        for (var j = 0; j < chkbox.length; j++) {
            var chkBoxNameStripSqrBraces = chkbox[j].name.replace('[]', ''); <----
	            if (inputNameArray.indexOf(chkBoxNameStripSqrBraces) === -1 && chkbox[j].checked === true) {
                chkboxTotal[parseInt(chkBoxNameStripSqrBraces.replace('chkboxGrp', ''))].innerHTML = "1";
                inputNameArray.push(chkBoxNameStripSqrBraces);
	            }
	

In PHP:

	if (isset($_POST['save'])) {
	$name01 = $_POST['chkboxGrp0[]'];
	$name01 = $_POST['chkboxGrp1[]'];
	}
	

Look at arrow in JavaScript, please

then goes on save in database...

As you can see Javascript use "name", but I need "name" in php to get data from form in HTML, but seem it won't work because of conflict. I'm sorry if you don't understand, I'm ASL user, not english. if still not understand, i will display all whole code.

Edited by Sigmahokies

Share this post


Link to post
Share on other sites

What's the purpose of that Javascript code, what are you doing there and why?  You should processing all of the submitted data in PHP, not Javascript.

In PHP, don't make the brackets part of the name.  It will already be an array.  It's just $_POST['chkboxGrp0'].

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...