1

The code i want to get into a php statement is

<a href="javascript:void();"
   onclick="document.loginfrm.user.value="username";
   document.loginfrm.pass.value="password";
   document.loginfrm.submit();">login
</a>

So what i would normally do is just surround it with an echo and quotation marks: an then replace any quotation marks in the statement with these --> ('), so that's what i did... and for some reason it seems to misinterpret the sentence severely. Here is the code i enter in php.

   echo "<a href='javascript:void();'
   onclick='document.loginfrm.user.value='username';
   document.loginfrm.pass.value='password';
   document.loginfrm.submit();'>". login ."</a>";

And this is how the browser interprets it:

    <a href="javascript:void();
" onclick="document.loginfrm.user.value=" username';="" 
document.loginfrm.pass.value="password" ;="" document.loginfrm.submit();'="">
login</a>

So yes is there any way around displaying html within php that could get around this problem

4 Answers 4

1

Can you try this, added \

    echo "<a href=\"javascript:void();\"
       onclick=\"document.loginfrm.user.value='username';
       document.loginfrm.pass.value=password';
       document.loginfrm.submit();\">login </a>";
Sign up to request clarification or add additional context in comments.

Comments

1

You need to escape it properly. Try

echo "<a href=\"javascript:void();\"
   onclick=\"document.loginfrm.user.value='username';
   document.loginfrm.pass.value='password';
   document.loginfrm.submit();\">". $login ."</a>";

Comments

1

You're not escaping your quotes. Try:

echo "<a href=\"javascript:void();\"
onclick=\"document.loginfrm.user.value='username';
document.loginfrm.pass.value='password';
document.loginfrm.submit();\">". login ."</a>";

which should produce:

<a href="javascript:void();"
   onclick="document.loginfrm.user.value='username';
   document.loginfrm.pass.value='password';
   document.loginfrm.submit();">login
</a>

As you have it now, you're closing the onclick attribute when you hit the quote at the start of the "username" value, which means the browser is interpreting username as another attribute and it just gets more confused from there...

Edit: sorry, fixed the html, rather than the php code...

Comments

0

You should do something like this..

<a href="javascript:void();"
   onclick="document.loginfrm.user.value='username';
   document.loginfrm.pass.value='password';
   document.loginfrm.submit();">login
</a>

and with php it should be

echo '<a href="javascript:void();"
          onclick="document.loginfrm.user.value=\"username\";
          document.loginfrm.pass.value=\"password\";
          document.loginfrm.submit();">
          login
      </a>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.