0

I have a script that pulls data from a form when it's submitted and passes that data to the next page.

On that page it displays the text...

<script type="text/javascript">formData.display("name")</script>

So it prints the name that the user gave earlier.

So I tried putting that into a textbox to pre-populate it....

<input class="text" type="text" name="name" value="<script type="text/javascript">formData.display("name")</script>" />

Unfortunately it just shows the code rather than the actual name.

So is there an easy way for me to get the text that displays with

<script type="text/javascript">formData.display("name")</script>

and put that into a textbox?

2
  • add a fiddle that will be helpful. Commented Aug 1, 2014 at 9:36
  • Please re edit your question; Make it more readable. Commented Aug 1, 2014 at 9:38

2 Answers 2

2

Javascript does not work that way...

Add an id to the input html:

<input id="myInputBox" class="text" type="text" name="name" value="" />

Just do this javascript onLoad:

var elem = document.getElementById("myInputBox");
elem.value = "My value";

Check the fiddle: http://jsfiddle.net/ve65v/

Sign up to request clarification or add additional context in comments.

Comments

0

Hi its hard way you are trying to achieve. One way is how @Trader provided other is to use templates and call it through JS. Following is fiddle for it. Hope it will be helpful

// HTML
<script id="template">
    <input class="text" type="text" name="name" value="{{user}}" />
</script>

<div id="render"></div>

// JS
var user = "Anil"
var template = $("#template").html()
template = template.replace("{{user}}", user)

$("#render").html(template)

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.