Jump to content

javascript in php

- - - - -

  • Please log in to reply
6 replies to this topic

#1
Bertan

Bertan

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
I'm trying to put some javascript in my php code. I'm having this textarea and I want the text within it to be selected if the user clicks within the textarea. But I just can't seem to get it work.

Anyone can help me on this one?


echo "<form method=\"post\" action=\"\">";

echo "<textarea id=\"glitter\" cols=\"50\" onClick=\"javascript:this.form.comments.focus();this.form.comments.select();\">";

echo "<p>This text should be all selected if the user clicks within the textarea</p>";

echo "</textarea>";

echo "</form>";}



#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
hmm.. not sure that you shall have javascript: in the onClick event, it's obvious that it's meant to be script. javascript: is used in href:s.

another thing. instead of escaping all those quotation marks, use apostrophes around the text, and you don't have to escape it.

example:
echo '<a href="http://www.codecall.net" target="_blank">CodeCall</a>';

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
Bertan

Bertan

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
I had this code working with a html file, so i figured it would be working with php as well. Either way, if this is not the best solution, can anyone help me with another way to solve this problem.

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
it should work then. what is it that isn't working? just the script part? can you see that the generated source is correct?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
Bertan

Bertan

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
All but the script is working.

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Hi Bertan,

It appears you are referencing a different form and it cannot work, try this:
<?php
echo "<form method=\"post\" action=\"\">";
echo "<textarea id=\"glitter\" cols=\"50\" onClick=\"this.focus();this.select();\">";
echo "<p>This text should be all selected if the user clicks within the textarea</p>";
echo "</textarea>";
echo "</form>";
?>

Hope this helps!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
Bertan

Bertan

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
Thanks, it works now. :c-smile:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users