unknown00 Posted July 11, 2011 Share Posted July 11, 2011 not sure what section to post this in, basically i have html in a javascript function that i want to pass into a php. here is some of my javascript code var names = document.getElementById('names').value; var nms = names.split(";;") for (i=0; i<las.length; i++) { var contentString = [ '<div id="tab-1">', '<p><h1>'+nms[i]+'</h1></p>', '</div>' +'<form action="index.php" method="post" enctype="multipart/form-data">'+ '<input id="delbutton" name="delbutton" type="submit" value="Delete">',+'</form>' } then when the button gets pressed it goes to if(isset($_POST['delbutton'])=='Delete') { echo("into the php delete: " . $_POST['name2'] . "<br />\n"); echo '<pre>' . print_r($_POST,true) . '</pre>'; } basically i want to be able to access the value of nms in the php call. i am able to pass anything in <input> tags like normal html, but i want to get nms to go through what should i do? Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/ Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 +'<form action="index.php?nms='+nms[$i]+'" method="post" enctype="multipart/form-data">'+ then on your php: if(isset($_POST['delbutton'])=='Delete') { echo("into the php delete: " . $_POST['name2'] . "<br />\n"); echo '<pre>' . print_r($_POST,true) . '</pre>'; echo $_GET[''nms]; } Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241358 Share on other sites More sharing options...
unknown00 Posted July 11, 2011 Author Share Posted July 11, 2011 doesn't work, actually messes up my form display Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241386 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 typo , should be echo $_GET['nms']; and what is the address in the url when you click on the button to post the form Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241392 Share on other sites More sharing options...
unknown00 Posted July 11, 2011 Author Share Posted July 11, 2011 typo , should be echo $_GET['nms']; and what is the address in the url when you click on the button to post the form yea i caught that typo. the form doesn't appear anymore, i don't know why, so to answer your question no url Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241396 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 ok, why cant you pass a hidden input type through? +'<input id="nms" name="nms" type="hidden" value="'+nms[$i]+'"/>' Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241400 Share on other sites More sharing options...
unknown00 Posted July 11, 2011 Author Share Posted July 11, 2011 nope, form doesn't appear again. it seems like when '+nms[$i]+' is used it screws everything up and nothing works properly Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241408 Share on other sites More sharing options...
premiso Posted July 11, 2011 Share Posted July 11, 2011 Shouldn't it just be i not $i, as you are doing this on the JS side of things? Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241409 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 premiso is right, it should be i not $i. Ive got php on the brain today. My bad Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1241413 Share on other sites More sharing options...
unknown00 Posted July 13, 2011 Author Share Posted July 13, 2011 one quick comment - i get a hanging NaN. any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/241698-pass-dynamic-text-from-html-in-javascript-to-php/#findComment-1242332 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.