Javascript problem

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

how would i use document.write to write this input box? i can do it without
quotes but i need them for my purpose

<input type="textbox" name="input" value="something">

i did this but it doesn't have the double quotes
document.write( '<input type="textbox" name="input" ' + 'value="' +
entereddata+ '">');

2.
filter(enetereddate);
how can i filter out single quotes double quotes and other character that
might cause problem from a string? this string will be added to the value
param of the textbox.

this will cause problem, say i enetered this in a textbox

sjdkfjdfkd "dfdfd" dfdfd

when i do document.write and write this to the value parameter of the new
textbox it will be like this

<input type=textbox name=input value=sjdkfjdfkd "dfdfd" dfdfd>

i would like a function that can replace the quotes in the input string to
&quot;
and also any other harmful characters


Thanks in advance,
Aaron
 
Hi,

First off, these are not the most appropriate groups for your question, but
anyway - see inline:

Aaron said:
how would i use document.write to write this input box? i can do it without
quotes but i need them for my purpose

<input type="textbox" name="input" value="something">

i did this but it doesn't have the double quotes
document.write( '<input type="textbox" name="input" ' + 'value="' +
entereddata+ '">');

You need to escape the quotes:

document.write( "<input type=\"textbox\" name=\"input\" value=\"" +
entereddata+ "\">");
2.
filter(enetereddate);
how can i filter out single quotes double quotes and other character that
might cause problem from a string? this string will be added to the value
param of the textbox.

this will cause problem, say i enetered this in a textbox

sjdkfjdfkd "dfdfd" dfdfd

when i do document.write and write this to the value parameter of the new
textbox it will be like this

<input type=textbox name=input value=sjdkfjdfkd "dfdfd" dfdfd>

If you use only double quotes you will need to escape only the double quotes
(it's easier). There is no ready function in jscript for this, but you can
use the replace function:

var v = "some \"NEW\" test";
var quot = new RegExp("\"", "g");
document.write("<input type=\"text\" id=\"input\" value=\"" +
v.replace(quot, "&quot;") + "\"><br/>");

Hope this helps
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top