Solved

Javascript - Using function repeatedly

Posted on 2011-02-13
4
261 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:
gurvinder372 earned 250 total points
Comment Utility
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
Comment Utility
@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
Comment Utility
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
Comment Utility
Long overdue.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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.…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now