Reputation: 1869
I have a website that receives parameters in the URL address (www.xxx.html?name=David
)
then I assign the value to the html text like this:
<span name="uname" id="uname"> </span>, I'd like to thank you
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var userName = getParameterByName('uname');
document.getElementById("uname").textContent = userName;
});
</script>
up to this point everything works well
now when I try to read again the value in uname
in the PHP file in order to send it in the email I have two issues
emailText = $_POST['uname'];
HTML
file and js
file being loaded and can be debugged but the PHP
file doesn't exist in the file tree of the debugBUT it is being loaded and read because other variables are being read and sent correctly to the email.
Upvotes: 0
Views: 315
Reputation: 38609
If I need to get value of span ill do something like this
<span data-name="someTextHere">...</span> # data-name will not visible in browser unless page source mode
and you can access it by using ($(this).data('name'))
Ex
var userName = ($(this).data('name'));
And this article Submit Form Using Ajax, PHP and jQuery will helps
you to pass data without Undefined Index Error
.
Upvotes: 0
Reputation: 6848
When submitting a form the user agent (browser) will build a form data set from "Succesful controls".
A Control is one of the following:
Only these fields will be submitted when you submit a form. A <span>
is not part of that.
If you want to add a value with JavaScript to the form that is not inside of a text input, I suggest that you use a hidden input to do so.
<input name="uname" type="hidden" value="value">
When you edit the span, you should then also change this hidden field to the same value.
Upvotes: 3
Reputation: 267
You cannot use span with name attribute.
Read this https://www.w3schools.com/tags/tag_span.asp
If you want to post, use form + proper input element.
https://www.w3schools.com/html/html_form_input_types.asp
And still, it's not very clear you are really trying to do, show us the whole page ...
Upvotes: 1