Solved

Javascript - Using function repeatedly

Posted on 2011-02-13
4
266 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:
gurvinder372 earned 250 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

710 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