[SOLVED] Escaping Quotes for Javascript

Problems with the Windows version of XAMPP, questions, comments, and anything related.

[SOLVED] Escaping Quotes for Javascript

Postby Gadrin » 02. July 2009 21:23

Hello, I'm trying to ouput an INPUT with some built in Javascript. Unfortunately PHP requires either a
double-quote or single-quote around the string to delimit it.

However I can't get PHP to build the same string and output it using:

Code: Select all
<?php

$exp = "document.getElementsByName(\"Route\")[0].textContent=\"+\";";
echo $exp;

echo "<form name='LoopForm' onsubmit='' action='Bump-Up.php' method='post'>
      Level Up/Down Test <br><br>
      <input type='text' name='Level' value='1' /> <br><br>"
echo "<input type='submit' name='PlusButton' value= ' + '  onclick='$exp' />
      <input type='submit' name='MinusButton' value= ' - ' onclick='SetMinus();' />
      <span name='Route'></span></form>
   "
?>


Anyone have a suggestion on how to get it to work ?

Final Output I want:

Code: Select all
<input type='submit' name='PlusButton' value= ' + '  onclick='document.getElementsByName("Route")[0].textContent="+";' />


Which works fine if just in HTML.



.
Last edited by Gadrin on 03. July 2009 14:06, edited 1 time in total.
Gadrin
 
Posts: 27
Joined: 08. April 2009 23:43

Re: Escaping Quotes for Javascript

Postby Gadrin » 03. July 2009 14:06

Well, this works. Turns out the ECHO statement wasn't constructed properly.
Also needed a TEXTAREA rather than a SPAN to hold the value of ROUTE for
the php action page.

Code: Select all
<style>
   textarea {display:none;}
</style>


<?php

$plus  = "document.getElementsByName(\"Route\")[0].textContent=\"+\";document.forms[\"LoopForm\"].submit();";
$minus = "document.getElementsByName(\"Route\")[0].textContent=\"-\";";

echo $plus;

echo "<form name='LoopForm' onsubmit='' action='Bump-Up.php' method='post'>
      Level Up/Down Test <br><br>
      <input type='text' name='Level' value='1' /> <br><br>";
echo    "<input type='submit' name='PlusButton' value= ' + '  onclick='$plus' />
      <input type='submit' name='MinusButton' value= ' - '  onclick='$minus' /><textarea name='Route'></textarea></form>";
?>


>
Gadrin
 
Posts: 27
Joined: 08. April 2009 23:43


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 86 guests

cron