Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript - Using function repeatedly

Posted on 2011-02-13
4
Medium Priority
?
271 Views
Last Modified: 2012-05-11
How to use the return of the function in simplified way? The code below returns true or false. I'd like to put it into a php variable and have this occur on the loading of the page.

<html>
<head>
<script type="text/javascript">
function supports_input_placeholder ( )
{
	var i = document.createElement("input");
	return "placeholder" in i;
}
</script>
</head>
<body>

<script type="text/javascript">
document.write(supports_input_placeholder())
</script>

</body>
</html>

Open in new window


To be used later like:
<input type="text" <?php if $place_holder { echo "placeholder=\"10 digit number\""; } maxlength="16" />

Open in new window

I do know one is server side and one is client side.

Thanks
0
Comment
Question by:dolan2go
  • 3
4 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1000 total points
ID: 34883721
if you want to make it work at page load event, then you need to call this method in the onload event

<html>
<head>
<script type="text/javascript">
function supports_input_placeholder ( )
{
      var i = document.createElement("input");
      return "placeholder" in i;
}
</script>
</head>
<body onload="supports_input_placeholder ( )">
</body>
</html>

to use php variable in javascript, check this
http://www.the-art-of-web.com/php/javascript-escape/
0
 
LVL 1

Author Comment

by:dolan2go
ID: 34883790
@gurvinder372,

How to put the return into a php variable or Session variable? Like $place_holder in the one line of code <input> above.
0
 
LVL 1

Author Comment

by:dolan2go
ID: 34884227
The intent is to arrive at a simpler (and working) method of this:

	<input type="text" name="text" <script type="text/javascript"> var p = s_i_p(); if (p == true) { document.write("placeholder=\"10 digit number\""); } </script> class="input_phone" maxlength="16" />

Open in new window

in lieu of:
<input type="text" name="text" placeholder="10 digit number" class="input_phone" maxlength="16" />

Open in new window

only if the function supports_input_placeholder() returns 'true'.
0
 
LVL 1

Author Closing Comment

by:dolan2go
ID: 35951579
Long overdue.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question