Solved

Javascript - Using function repeatedly

Posted on 2011-02-13
4
262 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

895 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

13 Experts available now in Live!

Get 1:1 Help Now