Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript - Using function repeatedly

Posted on 2011-02-13
4
Medium Priority
?
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

704 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