/    Sign up×
Community /Pin to ProfileBookmark

HTML5 Custom attribute question

Hello everyone,

Quick question, can an HTML5 Custom attribute be posted to another page? Like what you would do with php’s $_POST method?

If so, how can you use the data on the linked page, how would you call it?

Thanks ?

to post a comment
HTML

5 Comments(s)

Copy linkTweet thisAlerts:
@iBeZiApr 03.2013 — The data attribute can only be used in JavaScript, if you want to pass it to another page you could do so by appending the value in the URL as a $_GET variable or by using AJAX.
Copy linkTweet thisAlerts:
@Sub_SevenauthorApr 03.2013 — Yeah, that's what I thought, I know about $_GET but I'm trying to keep the URL as clean as possible.

I have never ever used AJAX for anything, is it complicated to do it this way?
Copy linkTweet thisAlerts:
@iBeZiApr 03.2013 — AJAX is used to send a request out to another page of your website receiving some kind of response back, without leaving the page the request was sent from.

It isn't particularly difficult, it just might not be what you're after.

Here's a quick ajax example, you open the page you want to send the request to appending your variables into the URL, then send the request, wait for a response, then do whatever with the response you get from the page.

<i>
</i>var ajax = new XMLHttpRequest;
ajax.open("GET","/ajaxrequestpage.php?myvar="+data,true);
ajax.send();
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 &amp;&amp; ajax.status == 200) {
alert(ajax.response);
}
};
Copy linkTweet thisAlerts:
@Sub_SevenauthorApr 03.2013 — Yeah, that might not do what I need, I'll look into it a little further, might be a good chance to start learning a little AJAX though...

Thanks ?
Copy linkTweet thisAlerts:
@tejasApr 05.2013 — Custom attributes are among the most significant additions for HTML5, and can play a major role in semantic Web development.

If you don’t already have one you want to use, copy the following outline into an HTML file:

<!DOCTYPE html>

<html>

<head>

<script>

/*functions here*/

</script>

</head>

<body>

</body>

</html>

You will place your elements with custom attributes in the body and the JavaScript functions for accessing them in the head section script area.

For Creating Element:

<div id="product1" data-product-category="clothing">

Cotton Shirt

</div>

<input type="button" value="get attribute" onclick="getElementAttribute('product1')"/>
×

Success!

Help @Sub_Seven spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...