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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×