Link to home
Start Free TrialLog in
Avatar of dolan2go
dolan2goFlag for United States of America

asked on

Javascript - Using function repeatedly

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
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dolan2go

ASKER

@gurvinder372,

How to put the return into a php variable or Session variable? Like $place_holder in the one line of code <input> above.
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'.
Long overdue.